Skip to content

Commit

Permalink
fix(roaring64): art_find_at would return the wrong leaf (#553)
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 incorrect leaf, rather than returning NULL

Fixes #552
  • Loading branch information
Dr-Emann authored Jan 14, 2024
2 parents e861d74 + 384903f commit bb9b90f
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 @@ -205,6 +205,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 @@ -223,6 +224,15 @@ DEFINE_TEST(test_add_range_closed) {
assert_true(roaring64_bitmap_contains(r, 100));
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 bb9b90f

Please sign in to comment.