From: Jens Axboe Date: Mon, 14 Apr 2014 15:45:19 +0000 (-0600) Subject: eta: fix potential divide by zero X-Git-Tag: fio-2.1.9~49 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=476882d7947f650783b255a8da74954069af90de;p=fio.git eta: fix potential divide by zero Signed-off-by: Jens Axboe --- diff --git a/eta.c b/eta.c index 42066e0d..7500082f 100644 --- a/eta.c +++ b/eta.c @@ -174,14 +174,26 @@ static int thread_eta(struct thread_data *td) double perc, perc_t; bytes_done = ddir_rw_sum(td->io_bytes); - perc = (double) bytes_done / (double) bytes_total; - if (perc > 1.0) - perc = 1.0; + + if (bytes_total) { + perc = (double) bytes_done / (double) bytes_total; + if (perc > 1.0) + perc = 1.0; + } else + perc = 0.0; if (td->o.time_based) { - perc_t = (double) elapsed / (double) timeout; - if (perc_t < perc) - perc = perc_t; + if (timeout) { + perc_t = (double) elapsed / (double) timeout; + if (perc_t < perc) + perc = perc_t; + } else { + /* + * Will never hit, we can't have time_based + * without a timeout set. + */ + perc = 0.0; + } } eta_sec = (unsigned long) (elapsed * (1.0 / perc)) - elapsed;