From: Jens Axboe Date: Mon, 27 Jul 2015 18:26:12 +0000 (-0600) Subject: Fix potential divide-by-zero in calc_rate() X-Git-Tag: fio-2.2.10~32 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=1e271b21a989657bc569ea8174218ab371935fe8 Fix potential divide-by-zero in calc_rate() Signed-off-by: Jens Axboe --- diff --git a/eta.c b/eta.c index aed61ecc..f608c4e5 100644 --- a/eta.c +++ b/eta.c @@ -290,14 +290,19 @@ static void calc_rate(int unified_rw_rep, unsigned long mtime, int i; for (i = 0; i < DDIR_RWDIR_CNT; i++) { - unsigned long long diff; + unsigned long long diff, this_rate; diff = io_bytes[i] - prev_io_bytes[i]; + if (mtime) + this_rate = ((1000 * diff) / mtime) / 1024; + else + this_rate = 0; + if (unified_rw_rep) { rate[i] = 0; - rate[0] += ((1000 * diff) / mtime) / 1024; + rate[0] += this_rate; } else - rate[i] = ((1000 * diff) / mtime) / 1024; + rate[i] = this_rate; prev_io_bytes[i] = io_bytes[i]; }