Skip to content

Commit

Permalink
Fix use of uninitialized variable 's' (reported by Coverity)
Browse files Browse the repository at this point in the history
If the MAXREPEATS constant is set to be small, then the variable
's' could be left uninitialized and then used in computations.
  • Loading branch information
ssvb committed Feb 14, 2017
1 parent a2d7b42 commit a2cf6d7
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
{
Expand Down Expand Up @@ -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.);
Expand Down

0 comments on commit a2cf6d7

Please sign in to comment.