Refactor loop in dump_histogram()

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 <behlendorf1@llnl.gov>
Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Closes #14575
This commit is contained in:
Richard Yao 2023-03-06 09:48:42 -05:00 committed by Brian Behlendorf
parent 08641d9007
commit 37edc7ea98
1 changed files with 4 additions and 2 deletions

View File

@ -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;
}