Skip to content

Commit

Permalink
result_set bugfix
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dm-jrae committed Jun 26, 2015
1 parent 495f61f commit fb7588c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
1 change: 1 addition & 0 deletions COPYING
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ The BSD License

Copyright (c) 2008-2011 Marius Muja (mariusm@cs.ubc.ca). All rights reserved.
Copyright (c) 2008-2011 David G. Lowe (lowe@cs.ubc.ca). All rights reserved.
Copyright (c) 2015 Google Inc (Jack Rae, jwrae@google.com). All Rights Reserved.

This comment has been minimized.

Copy link
@stephematician

stephematician Sep 5, 2023

Unclear what the ramifications are of this claim to copyright.


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

Expand Down
4 changes: 1 addition & 3 deletions src/cpp/flann/util/result_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,10 @@ class KNNResultSet : public ResultSet<DistanceType>
#endif
{
// Check for duplicate indices
size_t j = i - 1;
while (dist_index_[j].dist_ == dist) {
for (size_t j = i - 1; dist_index_[j].dist_ == dist && j--;) {
if (dist_index_[j].index_ == index) {
return;
}
--j;
}
break;
}
Expand Down

0 comments on commit fb7588c

Please sign in to comment.