Merge pull request #245 from Dmitry-Me/ensureCapacityPreAsserts

Pre-asserts to ensure no overflow happens
This commit is contained in:
Lee Thomason 2014-12-22 11:27:43 -08:00
commit eaddfd8768
1 changed files with 2 additions and 0 deletions

View File

@ -288,7 +288,9 @@ public:
private:
void EnsureCapacity( int cap ) {
TIXMLASSERT( cap > 0 );
if ( cap > _allocated ) {
TIXMLASSERT( cap <= INT_MAX / 2 );
int newAllocated = cap * 2;
T* newMem = new T[newAllocated];
memcpy( newMem, _mem, sizeof(T)*_size ); // warning: not using constructors, only works for PODs