From 37edc7ea9881a0fcd3df67fe1e29d22ee4deb7a9 Mon Sep 17 00:00:00 2001 From: Richard Yao Date: Mon, 6 Mar 2023 09:48:42 -0500 Subject: [PATCH] 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 Signed-off-by: Richard Yao Closes #14575 --- cmd/zdb/zdb.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cmd/zdb/zdb.c b/cmd/zdb/zdb.c index 329562418b..9a0ffd25e7 100644 --- a/cmd/zdb/zdb.c +++ b/cmd/zdb/zdb.c @@ -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; }