From 0d485594167a9bf522ac8bae11adf621c5871cb7 Mon Sep 17 00:00:00 2001 From: Joel Watson Date: Wed, 11 Nov 2020 10:44:55 -0600 Subject: [PATCH] Length check is required here If one isn't included, then the nil check in the formatter never fails due to an empty slice being passed in, which causes the kv output to always get printed. --- command/snapshot/inspect/snapshot_inspect.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/command/snapshot/inspect/snapshot_inspect.go b/command/snapshot/inspect/snapshot_inspect.go index 61a641cf5b..468250fdab 100644 --- a/command/snapshot/inspect/snapshot_inspect.go +++ b/command/snapshot/inspect/snapshot_inspect.go @@ -189,8 +189,9 @@ func generateStats(info SnapshotInfo) []typeStats { // Generate the KV stats for the output struct that's // used to produce the printed output the user sees. func generateKVStats(info SnapshotInfo) []typeStats { - if info.StatsKV != nil { - ks := make([]typeStats, 0, len(info.StatsKV)) + kvLen := len(info.StatsKV) + if kvLen > 0 { + ks := make([]typeStats, 0, kvLen) for _, s := range info.StatsKV { ks = append(ks, s)