Skip to content

Commit d64bace

Browse files
author
Han Hu
committed
fix constructor and deconstructor of the node of the hierarchical_clustering_index tree.
This bug will cause the serialization of the hierarchical_clustering_index to crash. Because when saving the index, the pivot and pivot_index for the top node of each tree is not initializaed. then when load these top nodes, pivot = obj->points_[pivot_index]; will cause error that index is out of range.
1 parent d1a3d52 commit d64bace

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/cpp/flann/algorithms/hierarchical_clustering_index.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,10 @@ class HierarchicalClusteringIndex : public NNIndex<Distance>
361361
*/
362362
std::vector<PointInfo> points;
363363

364+
Node(){
365+
pivot = NULL;
366+
pivot_index = SIZE_MAX;
367+
}
364368
/**
365369
* destructor
366370
* calling Node destructor explicitly
@@ -369,6 +373,8 @@ class HierarchicalClusteringIndex : public NNIndex<Distance>
369373
{
370374
for(size_t i=0; i<childs.size(); i++){
371375
childs[i]->~Node();
376+
pivot = NULL;
377+
pivot_index = -1;
372378
}
373379
};
374380

@@ -380,7 +386,10 @@ class HierarchicalClusteringIndex : public NNIndex<Distance>
380386
Index* obj = static_cast<Index*>(ar.getObject());
381387
ar & pivot_index;
382388
if (Archive::is_loading::value) {
383-
pivot = obj->points_[pivot_index];
389+
if (pivot_index != SIZE_MAX)
390+
pivot = obj->points_[pivot_index];
391+
else
392+
pivot = NULL;
384393
}
385394
size_t childs_size;
386395
if (Archive::is_saving::value) {

0 commit comments

Comments
 (0)