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 <daniel.verkamp@intel.com>
Reviewed-on: https://review.gerrithub.io/364530
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Daniel Verkamp 2017-06-07 16:26:49 -07:00
parent f30f09e994
commit 8037bc0df3

View File

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