diff --git a/src/avalanche/peermanager.cpp b/src/avalanche/peermanager.cpp --- a/src/avalanche/peermanager.cpp +++ b/src/avalanche/peermanager.cpp @@ -70,6 +70,7 @@ // Guesstimate the position of the slot. size_t i = begin + ((slot - bottom) * (end - begin) / (top - bottom)); + assert(begin <= i && i < end); // We have a match. if (slots[i].contains(slot)) { @@ -79,6 +80,10 @@ // We undershooted. if (slots[i].precedes(slot)) { begin = i + 1; + if (begin >= end) { + return NO_PEER; + } + bottom = slots[begin].getStart(); continue; }