From: Bart Van Assche Date: Sat, 11 Jan 2020 23:42:49 +0000 (-0800) Subject: t/read-to-pipe-async: Do not divide by zero X-Git-Tag: fio-3.18~12^2~1 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=b38cc6cb679e2f48dbdef43b1d70b7a1f9278945;p=fio.git t/read-to-pipe-async: Do not divide by zero This patch fixes the following Coverity complaint: 23. zero_return: Function call utime_since(&s, &re) returns 0. CID 280732 (#2 of 2): Division or modulo by zero (DIVIDE_BY_ZERO) 24. divide_by_zero: In expression bytes * 1000UL * 1000UL / utime_since(&s, &re), division by expression utime_since(&s, &re) which may be zero has undefined behavior. Signed-off-by: Bart Van Assche --- diff --git a/t/read-to-pipe-async.c b/t/read-to-pipe-async.c index bc7986f7..1370ef08 100644 --- a/t/read-to-pipe-async.c +++ b/t/read-to-pipe-async.c @@ -581,6 +581,7 @@ int main(int argc, char *argv[]) struct reader_thread *rt; struct writer_thread *wt; unsigned long rate; + uint64_t elapsed; struct stat sb; size_t bytes; off_t off; @@ -684,9 +685,11 @@ int main(int argc, char *argv[]) show_latencies(&wt->s, "WRITERS"); bytes /= 1024; - rate = (bytes * 1000UL * 1000UL) / utime_since(&s, &re); + elapsed = utime_since(&s, &re); + rate = elapsed ? (bytes * 1000UL * 1000UL) / elapsed : 0; fprintf(stderr, "Read rate (KiB/sec) : %lu\n", rate); - rate = (bytes * 1000UL * 1000UL) / utime_since(&s, &we); + elapsed = utime_since(&s, &we); + rate = elapsed ? (bytes * 1000UL * 1000UL) / elapsed : 0; fprintf(stderr, "Write rate (KiB/sec): %lu\n", rate); close(fd);