From 4f1b9570602c069746a9d63197df29e8b5195df2 Mon Sep 17 00:00:00 2001 From: "Enrico Loparco (eloparco)" Date: Thu, 24 Jun 2021 00:54:34 +0200 Subject: [HICN-711] Add tests for listener table and size check in bitmap Signed-off-by: Enrico Loparco (eloparco) Change-Id: I573477186fc9f0c294975b15b1c908444d5c5559 --- hicn-light/src/hicn/base/bitmap.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'hicn-light/src/hicn/base/bitmap.h') diff --git a/hicn-light/src/hicn/base/bitmap.h b/hicn-light/src/hicn/base/bitmap.h index 908b28d87..46d473ff8 100644 --- a/hicn-light/src/hicn/base/bitmap.h +++ b/hicn-light/src/hicn/base/bitmap.h @@ -65,6 +65,13 @@ bitmap_ensure_pos(bitmap_t ** bitmap, off_t pos) return vector_ensure_pos(*bitmap, offset); } +/** + * @brief Returns the allocated size of a bitmap. + * + * @see listener_table_get_by_id + */ +#define bitmap_get_alloc_size(bitmap) vector_get_alloc_size(bitmap) + /** * @brief Retrieve the state of the i-th bit in the bitmap. * @@ -76,6 +83,7 @@ int bitmap_get(const bitmap_t * bitmap, off_t i) { size_t offset = i / BITMAP_WIDTH(bitmap); + assert(offset < bitmap_get_alloc_size(bitmap)); size_t pos = i % BITMAP_WIDTH(bitmap); size_t shift = BITMAP_WIDTH(bitmap) - pos - 1; return (bitmap[offset] >> shift) & 1; @@ -197,8 +205,4 @@ END: #define bitmap_free(bitmap) vector_free(bitmap) -#ifdef WITH_TESTS -#define bitmap_get_alloc_size(bitmap) vector_get_alloc_size(bitmap) -#endif /* WITH_TESTS */ - #endif /* UTIL_BITMAP_H */ -- cgit 1.2.3-korg