Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions tinyxml2.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,13 @@ class DynArray
TIXMLASSERT( cap > 0 );
if ( cap > _allocated ) {
TIXMLASSERT( cap <= SIZE_MAX / 2 / sizeof(T));
if ( cap > SIZE_MAX / 2 / sizeof(T) ) {
// cap*2 below would overflow size_t and wrap to a tiny
// value, giving a too-small allocation followed by an
// out-of-bounds memcpy. TIXMLASSERT is a no-op in release
// builds, so this needs to be a real check.
abort();
}
const size_t newAllocated = cap * 2;
T* newMem = new T[newAllocated];
TIXMLASSERT( newAllocated >= _size );
Expand Down