From 3ff8af57bb6fe312089ccfcbc95acf56d7b509a3 Mon Sep 17 00:00:00 2001 From: Adeel Kazmi Date: Thu, 14 Jul 2016 16:46:34 +0100 Subject: [PATCH] Avoid std::string crash when NULL is returned 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 | 2 ++ dali/internal/event/common/object-impl.cpp | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/automated-tests/src/dali/utc-Dali-GestureDetector.cpp b/automated-tests/src/dali/utc-Dali-GestureDetector.cpp index 911eabb38..2cbbcf102 100644 --- a/automated-tests/src/dali/utc-Dali-GestureDetector.cpp +++ b/automated-tests/src/dali/utc-Dali-GestureDetector.cpp @@ -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 ); diff --git a/dali/internal/event/common/object-impl.cpp b/dali/internal/event/common/object-impl.cpp index b384b8b8b..af52dc120 100644 --- a/dali/internal/event/common/object-impl.cpp +++ b/dali/internal/event/common/object-impl.cpp @@ -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 ) ) -- 2.34.1