You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If realloc is needed, the vector contents are moved to the newly allocated chunk of memory. This invalidates the previously obtained reference to the object that is to be pushed back. Then a copy constructor is called using this invalid reference. All this happens silently, i.e. leads to difficult to track critical bugs in the program. I checked the commit history, the bug seems to have been there for years.
Btw, void vector<T, Allocator>::DoInsertValue(const_iterator position, Args&&... args) works correctly:
::new((void*)(pNewData + nPosSize)) value_type(eastl::forward<Args>(args)...); // Because the old data is potentially being moved rather than copied, we need to move
pointer pNewEnd = eastl::uninitialized_move_ptr_if_noexcept(mpBegin, destPosition, pNewData); // the value first, because it might possibly be a reference to the old data being moved.
pNewEnd = eastl::uninitialized_move_ptr_if_noexcept(destPosition, mpEnd, ++pNewEnd); // Question: with exceptions disabled, do we assume all operations are noexcept and thus there's no need for uninitialized_move_ptr_if_noexcept?
The text was updated successfully, but these errors were encountered:
//here #524 is fixed!
::new((void*)(pNewData+(mpEnd-mpBegin))) value_type(eastl::forward<Args>(args)...); //first construct the new element in the destination buffer because the source might get moved away by the next line
pointer pNewEnd = eastl::uninitializedMove_ptr_if_noexcept(mpBegin, mpEnd, pNewData); //and here copy the rest of the elements into the new buffer
pNewEnd++;
BUT this will only fix the issue if you have exceptions disabled, when they're enabled it's NOT fixed (and I'm not confident enough to also fix the behaviour here).
Below steps to reproduce (MSVC 2022):
Expected output:
Actual output:
What happens:
void vector<T, Allocator>::DoInsertValueEnd(Args&&... args) does this:
If realloc is needed, the vector contents are moved to the newly allocated chunk of memory. This invalidates the previously obtained reference to the object that is to be pushed back. Then a copy constructor is called using this invalid reference. All this happens silently, i.e. leads to difficult to track critical bugs in the program. I checked the commit history, the bug seems to have been there for years.
Btw, void vector<T, Allocator>::DoInsertValue(const_iterator position, Args&&... args) works correctly:
The text was updated successfully, but these errors were encountered: