Skip to content

Commit f882781

Browse files
authored
Fix an index error in ArenaVectorBase (#3486)
Because `resize()` sets `usedElements` to its argument, we were accessing `data[usedElements]`, which can be outside of allocated memory depending the internal state, i.e., `allocatedElements`'s value. It is hard to come up with a test case for this because apparently the failure condition depends on the vector's internal state.
1 parent dc7184a commit f882781

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/mixed_arena.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ template<typename SubType, typename T> class ArenaVectorBase {
370370
void insertAt(size_t index, T item) {
371371
assert(index <= usedElements); // appending is ok
372372
resize(usedElements + 1);
373-
for (auto i = usedElements; i > index; --i) {
373+
for (auto i = usedElements - 1; i > index; --i) {
374374
data[i] = data[i - 1];
375375
}
376376
data[index] = item;

0 commit comments

Comments
 (0)