From a2cf6d7e382e3aea1eb39173174d9fa28cad15f3 Mon Sep 17 00:00:00 2001 From: Siarhei Siamashka Date: Tue, 14 Feb 2017 23:58:50 +0200 Subject: [PATCH] Fix use of uninitialized variable 's' (reported by Coverity) If the MAXREPEATS constant is set to be small, then the variable 's' could be left uninitialized and then used in computations. --- main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index de632cb..6205555 100644 --- a/main.c +++ b/main.c @@ -90,7 +90,7 @@ static double bandwidth_bench_helper(int64_t *dstbuf, int64_t *srcbuf, double s, s0, s1, s2; /* do up to MAXREPEATS measurements */ - s0 = s1 = s2 = 0; + s = s0 = s1 = s2 = 0; maxspeed = 0; for (n = 0; n < MAXREPEATS; n++) { @@ -139,7 +139,7 @@ static double bandwidth_bench_helper(int64_t *dstbuf, int64_t *srcbuf, } } - if (s / maxspeed * 100. >= 0.1) + if (maxspeed > 0 && s / maxspeed * 100. >= 0.1) { printf("%s%-52s : %8.1f MB/s (%.1f%%)\n", indent_prefix, description, maxspeed, s / maxspeed * 100.);