Skip to content

Commit a070bc5

Browse files
committed
Fix another invalid prefetch. Better output on range check error.
1 parent e23f6ca commit a070bc5

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

hnswlib/hnswalg.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,9 @@ class HierarchicalNSW : public AlgorithmInterface<dist_t> {
11111111
tableint *datal = (tableint *) (data + 1);
11121112
HNSWLIB_MM_PREFETCH(getDataByInternalId(*datal), _MM_HINT_T0);
11131113
for (int i = 0; i < size; i++) {
1114-
HNSWLIB_MM_PREFETCH(getDataByInternalId(*(datal + i + 1)), _MM_HINT_T0);
1114+
if (i + 1 < size) {
1115+
HNSWLIB_MM_PREFETCH(getDataByInternalId(*(datal + i + 1)), _MM_HINT_T0);
1116+
}
11151117
tableint cand = datal[i];
11161118
dist_t d = fstdistfunc_(dataPoint, getDataByInternalId(cand), dist_func_param_);
11171119
if (d < curdist) {

hnswlib/hnswlib.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,13 @@ class ChunkedArray {
437437
}
438438

439439
char* operator[](size_t i) const {
440+
#ifndef NDEBUG
441+
if (i >= getCapacity()) {
442+
HNSWERR << "Chunked array index out of range: i=" << i
443+
<< ", capacity=" << getCapacity() << std::endl;
444+
}
440445
assert(i < getCapacity());
446+
#endif
441447
if (i >= getCapacity()) return nullptr;
442448
size_t chunk_index = i / elements_per_chunk_;
443449
size_t index_in_chunk = i % elements_per_chunk_;

0 commit comments

Comments
 (0)