From 0956264f3dca6a0467092fe9ef335f3cae1c6177 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Mon, 14 Apr 2014 09:49:38 -0600 Subject: [PATCH] stat: fix potential divide-by-zero Signed-off-by: Jens Axboe --- stat.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/stat.c b/stat.c index ca733108..1ef88ddf 100644 --- a/stat.c +++ b/stat.c @@ -1803,7 +1803,11 @@ void add_bw_sample(struct thread_data *td, enum fio_ddir ddir, unsigned int bs, if (!delta) continue; /* No entries for interval */ - rate = delta * 1000 / spent / 1024; + if (spent) + rate = delta * 1000 / spent / 1024; + else + rate = 0; + add_stat_sample(&ts->bw_stat[ddir], rate); if (td->bw_log) @@ -1838,7 +1842,11 @@ void add_iops_sample(struct thread_data *td, enum fio_ddir ddir, unsigned int bs if (!delta) continue; /* No entries for interval */ - iops = (delta * 1000) / spent; + if (spent) + iops = (delta * 1000) / spent; + else + iops = 0; + add_stat_sample(&ts->iops_stat[ddir], iops); if (td->iops_log) -- 2.25.1