Fixed arithmetic exception when completedLength is 0.

pull/1/head
Tatsuhiro Tsujikawa 2010-12-04 20:56:52 +09:00
parent f3e89651a8
commit adcfffeccb
1 changed files with 4 additions and 3 deletions

View File

@ -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 = uint64_t completedLength = getCompletedLength();
((stat.getAllTimeUploadLength()*10)/getCompletedLength())/10.0; 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