[CodeCompletion] Fix incorrect upper bound for assertion

This assertion was bogus if there were fewer results than N.
This commit is contained in:
Ben Langmuir
2016-06-02 09:01:48 -07:00
parent 9433c390e8
commit 4600b1dd12
2 changed files with 11 additions and 1 deletions

View File

@@ -924,7 +924,7 @@ static void sortTopN(const Options &options, Group *group,
if (!beginNewIndex)
return;
assert(endNewIndex > beginNewIndex && endNewIndex < contents.size());
assert(endNewIndex > beginNewIndex && endNewIndex <= contents.size());
// Temporarily copy the first result to temporary storage.
SmallVector<Item *, 16> firstResults;
@@ -938,6 +938,7 @@ static void sortTopN(const Options &options, Group *group,
contents[ci] = std::unique_ptr<Item>(firstResults[i]);
}
unsigned topN = endNewIndex - beginNewIndex;
assert(topN <= options.showTopNonLiteralResults);
for (unsigned ci = topN, i = 0; i < beginNewIndex; ++i, ++ci) {
assert(ci < contents.size() && !contents[ci]);
contents[ci] = std::unique_ptr<Item>(firstResults[i]);