Skip to content

Commit

Permalink
roaring64: container_remove_range returns null rather than returning …
Browse files Browse the repository at this point in the history
…an empty container (#550)

This would lead to all sorts of issues: `typecode2` is read uninitialized, and hopefully just asserts that it's not one of the known typecodes. Then, we've stored a null container into the bitmap.
  • Loading branch information
Dr-Emann authored Jan 14, 2024
2 parents 433a04d + 1b7ab5c commit e861d74
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/roaring64.c
Original file line number Diff line number Diff line change
Expand Up @@ -538,13 +538,13 @@ static inline void remove_range_closed_at(art_t *art, uint8_t *high48,
leaf->container, leaf->typecode, min, max, &typecode2);
if (container2 != leaf->container) {
container_free(leaf->container, leaf->typecode);
leaf->container = container2;
leaf->typecode = typecode2;
}
if (!container_nonzero_cardinality(container2, typecode2)) {
art_erase(art, high48);
container_free(container2, typecode2);
free_leaf(leaf);
if (container2 != NULL) {
leaf->container = container2;
leaf->typecode = typecode2;
} else {
art_erase(art, high48);
free_leaf(leaf);
}
}
}

Expand Down
15 changes: 15 additions & 0 deletions tests/roaring64_unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,21 @@ DEFINE_TEST(test_remove_range_closed) {
assert_true(roaring64_bitmap_contains_bulk(r, &context, 300000));
roaring64_bitmap_free(r);
}
{
// Range completely clears the bitmap.
roaring64_bitmap_t* r = roaring64_bitmap_create();
// array container
roaring64_bitmap_add(r, 1);
// range container
roaring64_bitmap_add_range_closed(r, 0x10000, 0x20000);
// bitmap container
for (int i = 0x20000; i < 0x25000; i += 2) {
roaring64_bitmap_add(r, i);
}
roaring64_bitmap_remove_range_closed(r, 0, 0x30000);
assert_true(roaring64_bitmap_is_empty(r));
roaring64_bitmap_free(r);
}
}

DEFINE_TEST(test_get_cardinality) {
Expand Down

0 comments on commit e861d74

Please sign in to comment.