assert-pre-internal.h: add BT_ASSERT_PRE_VALID_INDEX()
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 23 Aug 2018 15:42:52 +0000 (11:42 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 2 May 2019 04:07:36 +0000 (00:07 -0400)
This new precondition assertion macro asserts that a given index is less
than a given length.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
include/babeltrace/assert-pre-internal.h

index 38f93a2e959c133503120ab97ca4ae243e514b72..e56d90ecc387b6e75854a357f5f095df42166d3c 100644 (file)
        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 */
This page took 0.02457 seconds and 4 git commands to generate.