Skip to content

Commit

Permalink
Refactor loop in dump_histogram()
Browse files Browse the repository at this point in the history
The current loop triggers a complaint that we are using an array offset
prior to a range check from cpp/offset-use-before-range-check when we
are actually calculating maximum and minimum values. I was about to file
a false positive report with CodeQL, but after looking at how the code
is structured, I really cannot blame CodeQL for mistaking this for a
range check.

Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Richard Yao <[email protected]>
Closes openzfs#14575
  • Loading branch information
ryao authored and behlendorf committed Mar 8, 2023
1 parent 08641d9 commit 37edc7e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions cmd/zdb/zdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1004,11 1004,13 @@ dump_histogram(const uint64_t *histo, int size, int offset)
uint64_t max = 0;

for (i = 0; i < size; i ) {
if (histo[i] == 0)
continue;
if (histo[i] > max)
max = histo[i];
if (histo[i] > 0 && i > maxidx)
if (i > maxidx)
maxidx = i;
if (histo[i] > 0 && i < minidx)
if (i < minidx)
minidx = i;
}

Expand Down

0 comments on commit 37edc7e

Please sign in to comment.