1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

fix divide by zero

This commit is contained in:
krepa098 2015-01-20 11:03:06 +01:00
parent 13e0a8a292
commit 2fa2fc1df5

View File

@ -137,14 +137,14 @@ void FileTransferWidget::onFileTransferInfo(ToxFile file)
qreal bytesPerSec = static_cast<int>(static_cast<qreal>(deltaBytes) / deltaSecs);
// calculate mean
meanData[meanIndex] = bytesPerSec;
meanIndex = (meanIndex + 1) % TRANSFER_ROLLING_AVG_COUNT;
meanIndex = meanIndex % TRANSFER_ROLLING_AVG_COUNT;
meanData[meanIndex++] = bytesPerSec;
qreal meanBytesPerSec = 0.0;
for(size_t i = 0; i < TRANSFER_ROLLING_AVG_COUNT; ++i)
meanBytesPerSec += meanData[i];
meanBytesPerSec /= qMin(static_cast<size_t>(meanIndex), static_cast<size_t>(TRANSFER_ROLLING_AVG_COUNT));
meanBytesPerSec /= static_cast<qreal>(TRANSFER_ROLLING_AVG_COUNT);
// update UI
if(meanBytesPerSec > 0)