Răsfoiți Sursa

Pre-asserts to ensure no overflow happens

Dmitry-Me 11 ani în urmă
părinte
comite
9fae869124
1 a modificat fișierele cu 2 adăugiri și 0 ștergeri
  1. 2 0
      tinyxml2.h

+ 2 - 0
tinyxml2.h

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