Fix off-by-one in Vector::insert.

This commit is contained in:
wolfbeast 2017-06-21 17:02:50 +02:00 committed by Roy Tam
commit 2a9f2dadee
2 changed files with 54 additions and 2 deletions

View file

@ -1232,10 +1232,10 @@ Vector<T, N, AP>::insert(T* aP, U&& aVal)
}
} else {
T oldBack = Move(back());
if (!append(Move(oldBack))) { /* Dup the last element. */
if (!append(Move(oldBack))) {
return nullptr;
}
for (size_t i = oldLength; i > pos; --i) {
for (size_t i = oldLength - 1; i > pos; --i) {
(*this)[i] = Move((*this)[i - 1]);
}
(*this)[pos] = Forward<U>(aVal);