Skip to content

Commit a2cf6d7

Browse files
committed
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.
1 parent a2d7b42 commit a2cf6d7

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ static double bandwidth_bench_helper(int64_t *dstbuf, int64_t *srcbuf,
9090
double s, s0, s1, s2;
9191

9292
/* do up to MAXREPEATS measurements */
93-
s0 = s1 = s2 = 0;
93+
s = s0 = s1 = s2 = 0;
9494
maxspeed = 0;
9595
for (n = 0; n < MAXREPEATS; n++)
9696
{
@@ -139,7 +139,7 @@ static double bandwidth_bench_helper(int64_t *dstbuf, int64_t *srcbuf,
139139
}
140140
}
141141

142-
if (s / maxspeed * 100. >= 0.1)
142+
if (maxspeed > 0 && s / maxspeed * 100. >= 0.1)
143143
{
144144
printf("%s%-52s : %8.1f MB/s (%.1f%%)\n", indent_prefix, description,
145145
maxspeed, s / maxspeed * 100.);

0 commit comments

Comments
 (0)