prevent memory corruption by calling erase on unallocated vector 61/24561/1
authorKimmo Hoikka <kimmo.hoikka@samsung.com>
Wed, 16 Jul 2014 12:09:56 +0000 (13:09 +0100)
committerKimmo Hoikka <kimmo.hoikka@samsung.com>
Wed, 16 Jul 2014 12:10:39 +0000 (13:10 +0100)
[Problem] potential memory corruption / crash
[Cause] not checking if vector internal buffer is allocated
[Solution] check

Change-Id: I299b7e6bd12ab8dc70ca3783ec8b823d37ba5b6f

dali/public-api/common/dali-vector.cpp

index 2b5e42d..e3f037f 100644 (file)
@@ -120,12 +120,16 @@ void VectorBase::Swap( VectorBase& vector )
 
 void VectorBase::Erase( char* address, SizeType elementSize )
 {
-  char* startAddress = address + elementSize;
-  const char* endAddress = reinterpret_cast< char* >( mData ) + Count() * elementSize;
-  SizeType numberOfBytes = endAddress - startAddress;
-  // addresses overlap so use memmove
-  memmove( address, startAddress, numberOfBytes );
-  SetCount( Count() - 1 );
+  // erase can be called on an unallocated vector
+  if( mData )
+  {
+    char* startAddress = address + elementSize;
+    const char* endAddress = reinterpret_cast< char* >( mData ) + Count() * elementSize;
+    SizeType numberOfBytes = endAddress - startAddress;
+    // addresses overlap so use memmove
+    memmove( address, startAddress, numberOfBytes );
+    SetCount( Count() - 1 );
+  }
 }
 
 } // namespace Dali