From 4d9c7e1c2f899930a0bef5f05391615875ff668c Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 26 Mar 2018 21:07:34 +1030 Subject: [PATCH] intmap: add test case which failed, extracted from real world usage. Because intmap_after_() would simply examine the critbits to walk the tree, it wouldn't realize that it might be in the completely wrong tree. In this case: Bit 4: 0 1 / \ / \ 100000011 100001011 When we ask for intmap_after_(011111111) we would check the critbit, it's a 1, so we end up on the right leaf instead of the left. Signed-off-by: Rusty Russell --- ccan/intmap/test/run-after-fail.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 ccan/intmap/test/run-after-fail.c diff --git a/ccan/intmap/test/run-after-fail.c b/ccan/intmap/test/run-after-fail.c new file mode 100644 index 00000000..4105b12f --- /dev/null +++ b/ccan/intmap/test/run-after-fail.c @@ -0,0 +1,26 @@ +#include +#include +#include + +int main(void) +{ + UINTMAP(const char *) map; + u64 idx; + + /* This is how many tests you plan to run */ + plan_tests(2); + + uintmap_init(&map); + assert(uintmap_add(&map, 0x103, "103")); + assert(uintmap_add(&map, 0x10b, "10b")); + + uintmap_first(&map, &idx); + ok1(idx > 0xF); + idx = 0xF; + ok1(strcmp(uintmap_after(&map, &idx), "103") == 0); + + uintmap_clear(&map); + + /* This exits depending on whether all tests passed */ + return exit_status(); +} -- 2.39.2