From 8037bc0df33fe0a65740df3a47e0752382a44267 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Wed, 7 Jun 2017 16:26:49 -0700 Subject: [PATCH] blobfs/tree: assert that array index is in bounds The math works out so that index is always in range here, but add an assert anyway to catch potential mistakes in the future and to placate scan-build. Change-Id: I09ad37dde56bc315543b3c142d91ca9a49e9b32c Signed-off-by: Daniel Verkamp Reviewed-on: https://review.gerrithub.io/364530 Tested-by: SPDK Automated Test System Reviewed-by: Ben Walker --- lib/blobfs/tree.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/blobfs/tree.c b/lib/blobfs/tree.c index fb14bcaee..efd87413f 100644 --- a/lib/blobfs/tree.c +++ b/lib/blobfs/tree.c @@ -97,6 +97,7 @@ spdk_tree_insert_buffer(struct cache_tree *root, struct cache_buffer *buffer) tree = root; while (tree->level > 0) { index = offset / CACHE_TREE_LEVEL_SIZE(tree->level); + assert(index < CACHE_TREE_WIDTH); offset &= CACHE_TREE_LEVEL_MASK(tree->level); if (tree->u.tree[index] == NULL) { tree->u.tree[index] = calloc(1, sizeof(*tree)); @@ -107,6 +108,7 @@ spdk_tree_insert_buffer(struct cache_tree *root, struct cache_buffer *buffer) } index = offset / CACHE_BUFFER_SIZE; + assert(index < CACHE_TREE_WIDTH); assert(tree->u.buffer[index] == NULL); tree->u.buffer[index] = buffer; tree->present_mask |= (1ULL << index);