From a4d5dfa328bb457698e4edfd24eac36f1fdfac01 Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Tue, 19 Jun 2007 00:08:06 +0000 Subject: [PATCH] avoid ridiculously rate divide-by-0 --- libtransmission/torrent.c | 6 +++++- macosx/Controller.m | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index 624c60991..2aeb4cfb8 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -663,7 +663,11 @@ float tr_torrentFileCompletion ( const tr_torrent_t * tor, int fileIndex ) { const uint64_t c = tr_torrentFileBytesCompleted ( tor, fileIndex ); - return (double)c / tor->info.files[fileIndex].length; + uint64_t length = tor->info.files[fileIndex].length; + + if( !length ) + return 1.0; + return (double)c / length; } float* diff --git a/macosx/Controller.m b/macosx/Controller.m index ce2847fd1..e1de0d813 100644 --- a/macosx/Controller.m +++ b/macosx/Controller.m @@ -161,8 +161,8 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy { fLib = tr_init("macosx"); - fTorrents = [[NSMutableArray alloc] initWithCapacity: 10]; - fDisplayedTorrents = [[NSMutableArray alloc] initWithCapacity: 10]; + fTorrents = [[NSMutableArray alloc] init]; + fDisplayedTorrents = [[NSMutableArray alloc] init]; fPendingTorrentDownloads = [[NSMutableDictionary alloc] init]; fDefaults = [NSUserDefaults standardUserDefaults];