Skip to content

Commit

Permalink
Fix segfault in roaring64 intersect_with_range
Browse files Browse the repository at this point in the history
Fixes #635
  • Loading branch information
Dr-Emann committed Jun 26, 2024
1 parent 54e1163 commit fd419ee
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/roaring/roaring_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <stdbool.h>
#include <stdint.h>

#include <roaring/portability.h>

#ifdef __cplusplus
Expand Down
2 changes: 1 addition & 1 deletion src/roaring64.c
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,7 @@ bool roaring64_bitmap_intersect_with_range(const roaring64_bitmap_t *r,
}
roaring64_iterator_t it;
roaring64_iterator_init_at(r, &it, /*first=*/true);
if (!roaring64_iterator_move_equalorlarger(&it, min)) {
if (!it.has_value || !roaring64_iterator_move_equalorlarger(&it, min)) {
return false;
}
return roaring64_iterator_has_value(&it) &&
Expand Down
12 changes: 12 additions & 0 deletions tests/roaring64_unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,11 @@ DEFINE_TEST(test_intersect) {
DEFINE_TEST(test_intersect_with_range) {
roaring64_bitmap_t* r = roaring64_bitmap_create();

// Empty bitmap never intersects
assert_false(roaring64_bitmap_intersect_with_range(r, 0, 0));
assert_false(roaring64_bitmap_intersect_with_range(r, 0, 50000));
assert_false(roaring64_bitmap_intersect_with_range(r, 0, UINT64_MAX));

roaring64_bitmap_add(r, 50000);
roaring64_bitmap_add(r, 100000);
roaring64_bitmap_add(r, 100001);
Expand All @@ -1065,6 +1070,13 @@ DEFINE_TEST(test_intersect_with_range) {
assert_true(roaring64_bitmap_intersect_with_range(r, 50001, 100001));
assert_false(roaring64_bitmap_intersect_with_range(r, 300001, UINT64_MAX));

// Empty ranges never intersect
assert_false(roaring64_bitmap_intersect_with_range(r, 0, 0));
assert_false(
roaring64_bitmap_intersect_with_range(r, UINT64_MAX, UINT64_MAX));
assert_false(roaring64_bitmap_intersect_with_range(r, UINT64_MAX, 0));
assert_false(roaring64_bitmap_intersect_with_range(r, 50000, 50000));

roaring64_bitmap_free(r);
}

Expand Down

0 comments on commit fd419ee

Please sign in to comment.