Skip to content

Commit dc360e8

Browse files
committed
FIX: Static tools & compiler warning on negative index access
1 parent 518b2b9 commit dc360e8

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

include/nanoflann.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,9 @@ class KNNResultSet
270270
//! full, or the maximum possible distance, if not full yet.
271271
DistanceType worstDist() const
272272
{
273-
return count < capacity ? std::numeric_limits<DistanceType>::max()
274-
: dists[count - 1];
273+
return (count < capacity || !count)
274+
? std::numeric_limits<DistanceType>::max()
275+
: dists[count - 1];
275276
}
276277

277278
void sort()
@@ -365,8 +366,8 @@ class RKNNResultSet
365366
//! full, or the maximum possible distance, if not full yet.
366367
DistanceType worstDist() const
367368
{
368-
return count < capacity ? maximumSearchDistanceSquared
369-
: dists[count - 1];
369+
return (count < capacity || !count) ? maximumSearchDistanceSquared
370+
: dists[count - 1];
370371
}
371372

372373
void sort()

0 commit comments

Comments
 (0)