avoid divide-by-0 in stats

This commit is contained in:
Mitchell Livingston 2007-11-26 19:18:00 +00:00
parent 6b5f1839aa
commit bf3bd6bd5d
2 changed files with 7 additions and 4 deletions

View File

@ -140,7 +140,7 @@ tr_getSessionStats( const tr_handle * handle,
{
const struct tr_stats_handle * stats = handle->sessionStats;
*setme = stats->single;
setme->ratio = (double)setme->uploadedMiB / (double)setme->downloadedMiB;
setme->ratio = setme->downloadedMiB ? (double)setme->uploadedMiB / (double)setme->downloadedMiB : TR_RATIO_NA;
setme->secondsActive += (time(NULL) - stats->startTime );
}
@ -150,7 +150,7 @@ tr_getCumulativeSessionStats( const tr_handle * handle,
{
const struct tr_stats_handle * stats = handle->sessionStats;
*setme = stats->cumulative;
setme->ratio = (double)setme->uploadedMiB / (double)setme->downloadedMiB;
setme->ratio = setme->downloadedMiB ? (double)setme->uploadedMiB / (double)setme->downloadedMiB : TR_RATIO_NA;
setme->secondsActive += (time(NULL) - stats->startTime );
}

View File

@ -88,8 +88,11 @@ tr_handle * fLib;
stringByAppendingString: NSLocalizedString(@" total", "stats total")]];
[fRatioField setStringValue: [NSString stringForRatio: statsSession.ratio]];
[fRatioAllField setStringValue: [[NSString stringForRatio: statsAll.ratio]
stringByAppendingString: NSLocalizedString(@" total", "stats total")]];
NSString * totalRatioString = statsAll.ratio != TR_RATIO_NA
? [[NSString stringForRatio: statsAll.ratio] stringByAppendingString: NSLocalizedString(@" total", "stats total")]
: NSLocalizedString(@"Total N/A", "stats total");
[fRatioAllField setStringValue: totalRatioString];
[fTimeField setStringValue: [self timeString: statsSession.secondsActive]];
[fTimeAllField setStringValue: [[self timeString: statsAll.secondsActive]