From f754e34e35718c5ce89739b9310b103901b9e313 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Wed, 10 Oct 2007 19:57:24 +0000 Subject: [PATCH] - BUGFIX: Fixed possible overflow in ETA calculation --- TODO | 3 ++- src/bittorrent.cpp | 16 +++++++++++----- src/src.pro | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/TODO b/TODO index 6275bd5ab..c111ab863 100644 --- a/TODO +++ b/TODO @@ -61,4 +61,5 @@ rc4->rc5 changelog: - BUGFIX: Now filtered don't appear on hard drive anymore (libtorrent >= r1659) - BUGFIX: AddInPause setting doesn't pause downloads on startup anymore -- BUGFIX: Fixed an ETA calculation problem when the torrent has filtered files \ No newline at end of file +- BUGFIX: Fixed an ETA calculation problem when the torrent has filtered files +- BUGFIX: Fixed possible overflow in ETA calculation \ No newline at end of file diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index d29e874ff..e8244c92c 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -147,7 +147,9 @@ void bittorrent::updateETAs() { if(listEtas.size() == ETAS_MAX_VALUES) { listEtas.removeFirst(); } - if(h.download_payload_rate()) { + // XXX: We can still get an overflow if remaining file size is approximately + // 8.38*10^5 TiB (lets assume this can't happen) + if(h.download_payload_rate() > 0.1) { listEtas << (qlonglong)((h.actual_size()-h.total_wanted_done())/(double)h.download_payload_rate()); ETAstats[hash] = listEtas; qlonglong moy = 0; @@ -156,12 +158,16 @@ void bittorrent::updateETAs() { Q_ASSERT(nbETAs); foreach(val, listEtas) { moy += (qlonglong)((double)val/(double)nbETAs); - if(moy < 0) break; + Q_ASSERT(moy >= 0); } - if(moy < 0) { + ETAs[hash] = moy; + } else { + // Speed is too low, we don't want overflow. + if(ETAstats.contains(hash)) { + ETAs.remove(hash); + } + if(ETAs.contains(hash)) { ETAs.remove(hash); - } else { - ETAs[hash] = moy; } } } diff --git a/src/src.pro b/src/src.pro index ecb86946e..999f74e73 100644 --- a/src/src.pro +++ b/src/src.pro @@ -11,7 +11,7 @@ TARGET = qbittorrent CONFIG += qt thread x11 network # Update this VERSION for each release -DEFINES += VERSION=\\\"v1.0.0rc4\\\" +DEFINES += VERSION=\\\"v1.0.0rc5\\\" DEFINES += VERSION_MAJOR=1 DEFINES += VERSION_MINOR=0 DEFINES += VERSION_BUGFIX=0