From c800eb3790218d2f33df01e77ec38cbd43cc02a1 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Thu, 23 Aug 2018 11:42:52 -0400 Subject: [PATCH] assert-pre-internal.h: add BT_ASSERT_PRE_VALID_INDEX() This new precondition assertion macro asserts that a given index is less than a given length. Signed-off-by: Philippe Proulx --- include/babeltrace/assert-pre-internal.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/babeltrace/assert-pre-internal.h b/include/babeltrace/assert-pre-internal.h index 38f93a2e..e56d90ec 100644 --- a/include/babeltrace/assert-pre-internal.h +++ b/include/babeltrace/assert-pre-internal.h @@ -117,4 +117,12 @@ BT_ASSERT_PRE(!(_obj)->frozen, "%s is frozen" _fmt, _obj_name, \ ##__VA_ARGS__) +/* + * Developer mode: asserts that a given index is less than a given size. + */ +#define BT_ASSERT_PRE_VALID_INDEX(_index, _length) \ + BT_ASSERT_PRE((_index) < (_length), \ + "Index is out of bounds: index=%" PRIu64 ", " \ + "count=%" PRIu64, (uint64_t) (_index), (uint64_t) (_length)) + #endif /* BABELTRACE_ASSERT_PRE_INTERNAL_H */ -- 2.34.1