Avoid std::string crash when NULL is returned 28/80128/1
authorAdeel Kazmi <adeel.kazmi@samsung.com>
Thu, 14 Jul 2016 15:46:34 +0000 (16:46 +0100)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Thu, 14 Jul 2016 16:24:13 +0000 (17:24 +0100)
GetDefaultPropertyName() can return NULL.
If we try to initialise a std::string with NULL, this causes an exception.

The solution is to just check that the returned value from GetDefaultPropertyName()
and return an empty std::string if it is NULL.

Change-Id: Iecf02228cade112b2922a0fbf0e9cef73a0df13d

automated-tests/src/dali/utc-Dali-GestureDetector.cpp
dali/internal/event/common/object-impl.cpp

index 911eabb..2cbbcf1 100644 (file)
@@ -460,6 +460,8 @@ int UtcDaliGestureDetectorProperties(void)
   Property::Value propValue = detector.GetProperty( DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX );
   DALI_TEST_EQUALS( propValue.GetType(), Property::NONE, TEST_LOCATION );
 
+  DALI_TEST_CHECK( detector.GetPropertyName( DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX ).empty() );
+
   // For coverage only, not testable
   detector.SetProperty( DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX, true );
 
index b384b8b..af52dc1 100644 (file)
@@ -164,7 +164,14 @@ std::string Object::GetPropertyName( Property::Index index ) const
 
   if ( index < DEFAULT_PROPERTY_MAX_COUNT )
   {
-    return GetDefaultPropertyName( index );
+    std::string string;
+
+    const char * propertyName = GetDefaultPropertyName( index );
+    if( propertyName )
+    {
+      string = propertyName;
+    }
+    return string;
   }
 
   if ( ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )