aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorDon Brady <[email protected]>2017-02-07 10:29:47 -0700
committerBrian Behlendorf <[email protected]>2017-02-07 09:29:47 -0800
commitcd5083c00c6215f4f15c04e30feeb5f9457ec896 (patch)
tree8c4065e367132cf5785ebce237ce1bb6d62afebb /cmd
parent582cc0141699991da38ba8bfc8eb938ecb2d9856 (diff)
Fix coverity defects: CID 155928
CID 155928: Integer handling issues (DIVIDE_BY_ZERO) In the current vdev label, the leaf count is always non-zero but it doesn't hurt to check the count for future proofing. Reviewed-by: George Melikov <[email protected]> Reviewed-by: Giuseppe Di Natale <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Don Brady <[email protected]> Closes #5749
Diffstat (limited to 'cmd')
-rw-r--r--cmd/zdb/zdb.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/cmd/zdb/zdb.c b/cmd/zdb/zdb.c
index d53cb2184..94b359029 100644
--- a/cmd/zdb/zdb.c
+++ b/cmd/zdb/zdb.c
@@ -2303,7 +2303,7 @@ dump_nvlist_stats(nvlist_t *nvl, size_t cap)
{
zdb_nvl_stats_t stats = { 0 };
size_t size, sum = 0, total;
- size_t noise, average;
+ size_t noise;
/* requires nvlist with non-unique names for stat collection */
VERIFY0(nvlist_alloc(&stats.zns_string, 0, 0));
@@ -2344,15 +2344,18 @@ dump_nvlist_stats(nvlist_t *nvl, size_t cap)
(void) printf("%12s %4d %6d bytes (%5.2f%%)\n\n", "nvlists:",
stats.zns_list_count, (int)size, 100.0 * size / total);
- average = stats.zns_leaf_total / stats.zns_leaf_count;
- (void) printf("%12s %4d %6d bytes average\n",
- "leaf vdevs:", stats.zns_leaf_count, (int)average);
- (void) printf("%24d bytes largest\n", (int)stats.zns_leaf_largest);
+ if (stats.zns_leaf_count > 0) {
+ size_t average = stats.zns_leaf_total / stats.zns_leaf_count;
- if (dump_opt['l'] >= 3)
- (void) printf(" space for %d additional leaf vdevs\n",
- (int)((cap - total) / average));
+ (void) printf("%12s %4d %6d bytes average\n", "leaf vdevs:",
+ stats.zns_leaf_count, (int)average);
+ (void) printf("%24d bytes largest\n",
+ (int)stats.zns_leaf_largest);
+ if (dump_opt['l'] >= 3 && average > 0)
+ (void) printf(" space for %d additional leaf vdevs\n",
+ (int)((cap - total) / average));
+ }
(void) printf("\n");
nvlist_free(stats.zns_string);