Pārlūkot izejas kodu

Fixed arithmetic exception when completedLength is 0.

Tatsuhiro Tsujikawa 15 gadi atpakaļ
vecāks
revīzija
adcfffeccb
1 mainītis faili ar 4 papildinājumiem un 3 dzēšanām
  1. 4 3
      src/RequestGroup.cc

+ 4 - 3
src/RequestGroup.cc

@@ -1201,15 +1201,16 @@ void RequestGroup::reportDownloadFinished()
 #ifdef ENABLE_BITTORRENT
   if(downloadContext_->hasAttribute(bittorrent::BITTORRENT)) {
     TransferStat stat = calculateStat();
-    double shareRatio =
-      ((stat.getAllTimeUploadLength()*10)/getCompletedLength())/10.0;
+    uint64_t completedLength = getCompletedLength();
+    double shareRatio = completedLength == 0 ? 0.0 :
+      1.0*stat.getAllTimeUploadLength()/completedLength;
     SharedHandle<TorrentAttribute> attrs =
       bittorrent::getTorrentAttrs(downloadContext_);
     if(!attrs->metadata.empty()) {
       A2_LOG_NOTICE(fmt(MSG_SHARE_RATIO_REPORT,
                         shareRatio,
                         util::abbrevSize(stat.getAllTimeUploadLength()).c_str(),
-                        util::abbrevSize(getCompletedLength()).c_str()));
+                        util::abbrevSize(completedLength).c_str()));
     }
   }
 #endif // ENABLE_BITTORRENT