]> git.sur5r.net Git - minitube/commitdiff
Fixed division by zero
authorFlavio <flavio@odisseo.local>
Thu, 27 Sep 2012 09:52:00 +0000 (11:52 +0200)
committerFlavio <flavio@odisseo.local>
Thu, 27 Sep 2012 09:52:00 +0000 (11:52 +0200)
src/downloaditem.cpp

index 6baab761a1291ec4d542d69623bd6cef27b6bf65..39132eb0eeaaaad4b73b830e4bd212270b965291 100644 (file)
@@ -204,7 +204,10 @@ void DownloadItem::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) {
             m_status = Downloading;
             emit statusChanged();
         } else {
-            int bufferPercent = bytesReceived * 100 / qMax(bufferSize, neededBytes);
+            int bytes = qMax(bufferSize, neededBytes);
+            int bufferPercent = 0;
+            if (bytes > 0)
+                bufferPercent = bytesReceived * 100 / bytes;
             emit bufferProgress(bufferPercent);
         }
 
@@ -262,7 +265,10 @@ double DownloadItem::remainingTime() const {
     if (m_finishedDownloading)
         return -1.0;
 
-    double timeRemaining = ((double)(bytesTotal() - bytesReceived())) / currentSpeed();
+    double speed = currentSpeed();
+    double timeRemaining = 0.0;
+    if (speed > 0.0)
+        timeRemaining = ((double)(bytesTotal() - bytesReceived())) / speed;
 
     // When downloading the eta should never be 0
     if (timeRemaining == 0)
@@ -275,7 +281,11 @@ double DownloadItem::currentSpeed() const {
     if (m_finishedDownloading)
         return -1.0;
 
-    return m_bytesReceived * 1000.0 / m_downloadTime.elapsed();
+    int elapsed = m_downloadTime.elapsed();
+    double speed = -1.0;
+    if (elapsed > 0)
+        speed = m_bytesReceived * 1000.0 / elapsed;
+    return speed;
 }
 
 void DownloadItem::requestFinished() {