瀏覽代碼

Fixed arithmetic exception when completedLength is 0.

Tatsuhiro Tsujikawa 15 年之前
父節點
當前提交
adcfffeccb
共有 1 個文件被更改,包括 4 次插入3 次删除
  1. 4 3
      src/RequestGroup.cc

+ 4 - 3
src/RequestGroup.cc

@@ -1201,15 +1201,16 @@ void RequestGroup::reportDownloadFinished()
 #ifdef ENABLE_BITTORRENT
 #ifdef ENABLE_BITTORRENT
   if(downloadContext_->hasAttribute(bittorrent::BITTORRENT)) {
   if(downloadContext_->hasAttribute(bittorrent::BITTORRENT)) {
     TransferStat stat = calculateStat();
     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 =
     SharedHandle<TorrentAttribute> attrs =
       bittorrent::getTorrentAttrs(downloadContext_);
       bittorrent::getTorrentAttrs(downloadContext_);
     if(!attrs->metadata.empty()) {
     if(!attrs->metadata.empty()) {
       A2_LOG_NOTICE(fmt(MSG_SHARE_RATIO_REPORT,
       A2_LOG_NOTICE(fmt(MSG_SHARE_RATIO_REPORT,
                         shareRatio,
                         shareRatio,
                         util::abbrevSize(stat.getAllTimeUploadLength()).c_str(),
                         util::abbrevSize(stat.getAllTimeUploadLength()).c_str(),
-                        util::abbrevSize(getCompletedLength()).c_str()));
+                        util::abbrevSize(completedLength).c_str()));
     }
     }
   }
   }
 #endif // ENABLE_BITTORRENT
 #endif // ENABLE_BITTORRENT