From: Flavio Date: Thu, 27 Sep 2012 09:52:00 +0000 (+0200) Subject: Fixed division by zero X-Git-Tag: 1.9~4 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=49e9f2d6338cddac72f24aa1cad926ae983a5a96;p=minitube Fixed division by zero --- diff --git a/src/downloaditem.cpp b/src/downloaditem.cpp index 6baab76..39132eb 100644 --- a/src/downloaditem.cpp +++ b/src/downloaditem.cpp @@ -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() {