Skip to content

Commit 1e22d35

Browse files
committed
fix segfault on empty points
1 parent b8a337e commit 1e22d35

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

include/kdbush.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ class KDBush {
5151
assert(points.empty());
5252
const TIndex size = static_cast<TIndex>(std::distance(points_begin, points_end));
5353

54+
if (size == 0) return;
55+
5456
points.reserve(size);
5557
ids.reserve(size);
5658

test.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,14 @@ static void testRadius() {
4242
assert(std::equal(expectedIds.begin(), expectedIds.end(), result.begin()));
4343
}
4444

45+
static void testEmpty() {
46+
auto emptyPoints = std::vector<TPoint>{};
47+
kdbush::KDBush<TPoint> index(emptyPoints);
48+
}
49+
4550
int main() {
4651
testRange();
4752
testRadius();
53+
testEmpty();
4854
return 0;
4955
}

0 commit comments

Comments
 (0)