fixing a potential memory corruption/crash if Dali::Vector is Resized before putting... 86/24086/1
authorKimmo Hoikka <kimmo.hoikka@samsung.com>
Sat, 21 Jun 2014 13:11:50 +0000 (14:11 +0100)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Tue, 8 Jul 2014 13:15:34 +0000 (14:15 +0100)
Change-Id: Idb66f6938421ca53ddc3199e0677f0bc87ceeceb
Signed-off-by: Adeel Kazmi <adeel.kazmi@samsung.com>
dali/public-api/common/dali-vector.cpp

index d2cb77a..2b5e42d 100644 (file)
@@ -61,10 +61,12 @@ void VectorBase::Release()
 
 void VectorBase::SetCount( SizeType count )
 {
-  // Setcount is internal so should not be called on empty vector
-  DALI_ASSERT_DEBUG( mData && "Vector is empty" );
-  SizeType* metadata = reinterpret_cast< SizeType* >( mData );
-  *(metadata - 1) = count;
+  // someone can call Resize( 0 ) before ever populating the vector
+  if( mData )
+  {
+    SizeType* metadata = reinterpret_cast< SizeType* >( mData );
+    *(metadata - 1) = count;
+  }
 }
 
 void VectorBase::Reserve( SizeType capacity, SizeType elementSize )