Skip to content

Commit

Permalink
fix(roaring64): art_find_at would return the wrong leaf
Browse files Browse the repository at this point in the history
If a leaf shared all but the last byte, art_find_at could return the incorrrect
leaf, rather than returning NULL

Fixes #552
  • Loading branch information
Dr-Emann committed Jan 14, 2024
1 parent f3ad2f2 commit 3fabeea
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/art/art.c
Original file line number Diff line number Diff line change
Expand Up @@ -1093,7 +1093,7 @@ static art_val_t *art_find_at(const art_node_t *node,
depth += inner_node->prefix_size + 1;
}
art_leaf_t *leaf = CAST_LEAF(node);
if (depth >= ART_KEY_BYTES - 1) {
if (depth >= ART_KEY_BYTES) {
return (art_val_t *)leaf;
}
uint8_t common_prefix =
Expand Down
10 changes: 10 additions & 0 deletions tests/roaring64_unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ DEFINE_TEST(test_add_range_closed) {
// Range spans more than two containers.
roaring64_bitmap_t* r = roaring64_bitmap_create();
roaring64_bitmap_add_range_closed(r, 100, 300000);
assert_int_equal(roaring64_bitmap_get_cardinality(r), 300000 - 100 + 1);
roaring64_bulk_context_t context{};
assert_false(roaring64_bitmap_contains_bulk(r, &context, 99));
for (uint64_t i = 100; i <= 300000; ++i) {
Expand All @@ -199,6 +200,15 @@ DEFINE_TEST(test_add_range_closed) {
assert_false(roaring64_bitmap_contains_bulk(r, &context, 300001));
roaring64_bitmap_free(r);
}
{
// Add a range that spans multiple ART levels (end >> 16 == 0x0101)
roaring64_bitmap_t* r = roaring64_bitmap_create();
uint64_t end = 0x101ffff;
uint64_t start = 0;
roaring64_bitmap_add_range_closed(r, start, end);
assert_int_equal(roaring64_bitmap_get_cardinality(r), end - start + 1);
roaring64_bitmap_free(r);
}
}

DEFINE_TEST(test_contains_bulk) {
Expand Down

0 comments on commit 3fabeea

Please sign in to comment.