diff --git a/libtransmission/stats.c b/libtransmission/stats.c index a8916b287..1ab4ff521 100644 --- a/libtransmission/stats.c +++ b/libtransmission/stats.c @@ -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 ); } diff --git a/macosx/StatsWindowController.m b/macosx/StatsWindowController.m index 6ccee04ad..053eb14a0 100644 --- a/macosx/StatsWindowController.m +++ b/macosx/StatsWindowController.m @@ -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]