Skip to content

Commit fb7588c

Browse files
committed
result_set bugfix
Zero-based boundary condition is not enforced for the variable size_t j, it was previously free to underflow. I have placed j-- as a condition within the for loop to enforce this. See this thread for considerations on good style for decrementing size_t loops: http://stackoverflow.com/questions/7224386/iterating-with-size-t-0-as-a-boundary-condition Placing the j-- at the beginning of the loop is equivalent to --j at the end, so the functionality is identical. Updated COPYING as this is standard / mandatory practice for Google employees' contributions to open source projects.
1 parent 495f61f commit fb7588c

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

COPYING

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ The BSD License
33

44
Copyright (c) 2008-2011 Marius Muja ([email protected]). All rights reserved.
55
Copyright (c) 2008-2011 David G. Lowe ([email protected]). All rights reserved.
6+
Copyright (c) 2015 Google Inc (Jack Rae, [email protected]). All Rights Reserved.
67

78
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
89

src/cpp/flann/util/result_set.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,12 +252,10 @@ class KNNResultSet : public ResultSet<DistanceType>
252252
#endif
253253
{
254254
// Check for duplicate indices
255-
size_t j = i - 1;
256-
while (dist_index_[j].dist_ == dist) {
255+
for (size_t j = i - 1; dist_index_[j].dist_ == dist && j--;) {
257256
if (dist_index_[j].index_ == index) {
258257
return;
259258
}
260-
--j;
261259
}
262260
break;
263261
}

0 commit comments

Comments
 (0)