[Tizen] Fix svace issue : Need to check Property::Value.Get() return 79/307479/1 accepted/tizen/8.0/unified/20240311.164645
authorEunki, Hong <eunkiki.hong@samsung.com>
Tue, 5 Mar 2024 00:43:05 +0000 (09:43 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Mon, 11 Mar 2024 02:34:41 +0000 (11:34 +0900)
It is possible that user set invalid value type. If then, we need to skip
given value setter.

Change-Id: I8bc339f30b969c049a0b07bda152c4d24593bb48
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
dali-toolkit/internal/controls/scroll-bar/scroll-bar-impl.cpp
dali-toolkit/internal/controls/slider/slider-impl.cpp
dali-toolkit/internal/controls/super-blur-view/super-blur-view-impl.cpp
dali-toolkit/internal/text/controller/text-controller-placeholder-handler.cpp

index 835ecc9..bf177fa 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -707,12 +707,22 @@ void ScrollBar::SetProperty(BaseObject* object, Property::Index index, const Pro
           Dali::Vector<float> positions;
           size_t              positionCount = array->Count();
           positions.Resize(positionCount);
+
+          bool valid = true;
           for(size_t i = 0; i != positionCount; ++i)
           {
-            array->GetElementAt(i).Get(positions[i]);
+            if(DALI_UNLIKELY(!array->GetElementAt(i).Get(positions[i])))
+            {
+              // Given array is invalid. Fast out.
+              valid = false;
+              break;
+            }
           }
 
-          scrollBarImpl.SetScrollPositionIntervals(positions);
+          if(DALI_LIKELY(valid))
+          {
+            scrollBarImpl.SetScrollPositionIntervals(positions);
+          }
         }
         break;
       }
index 633cc25..5de904f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -862,14 +862,16 @@ float Slider::SnapToMark(float value)
   for(MarkList::SizeType i = 0; i < mMarks.Count(); ++i)
   {
     const Property::Value& propertyValue = mMarks[i];
-    propertyValue.Get(mark);
-    mark = MapValuePercentage(mark);
-
-    float dist = fabsf(mark - value);
-    if(dist < closestDist)
+    if(propertyValue.Get(mark))
     {
-      closestDist = dist;
-      closestMark = mark;
+      mark = MapValuePercentage(mark);
+
+      float dist = fabsf(mark - value);
+      if(dist < closestDist)
+      {
+        closestDist = dist;
+        closestMark = mark;
+      }
     }
   }
 
@@ -891,22 +893,24 @@ bool Slider::MarkReached(float value, int& outIndex)
     current = head + (tail - head) / 2;
 
     const Property::Value& propertyValue = mMarks[current];
-    propertyValue.Get(mark);
-    mark = MapValuePercentage(mark);
-
-    if(fabsf(mark - value) < MARK_TOLERANCE)
+    if(propertyValue.Get(mark))
     {
-      outIndex = current;
-      return true;
-    }
+      mark = MapValuePercentage(mark);
 
-    if(value < mark)
-    {
-      tail = current - 1;
-    }
-    else
-    {
-      head = current + 1;
+      if(fabsf(mark - value) < MARK_TOLERANCE)
+      {
+        outIndex = current;
+        return true;
+      }
+
+      if(value < mark)
+      {
+        tail = current - 1;
+      }
+      else
+      {
+        head = current + 1;
+      }
     }
   }
 
index 7ea1492..907e7e0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -192,7 +192,7 @@ void SuperBlurView::SetBlurStrength(float blurStrength)
 
 float SuperBlurView::GetCurrentBlurStrength() const
 {
-  float blurStrength;
+  float blurStrength = 0.0f;
   (Self().GetProperty(mBlurStrengthPropertyIndex)).Get(blurStrength);
 
   return blurStrength;
index a0f03a6..d6d2acc 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -44,6 +44,54 @@ const char* const PLACEHOLDER_POINT_SIZE   = "pointSize";
 const char* const PLACEHOLDER_PIXEL_SIZE   = "pixelSize";
 const char* const PLACEHOLDER_ELLIPSIS     = "ellipsis";
 
+/**
+ * Convert all string keys to int keys
+ * @param[in] key The key to convert
+ * @return the index key supplied or matching, or INVALID_INDEX if no match
+ */
+static Dali::Property::Index GetIntKey(const Dali::Property::Key& key)
+{
+  if(key.type == Dali::Property::Key::INDEX)
+  {
+    return key.indexKey;
+  }
+
+  if(key.stringKey == PLACEHOLDER_TEXT)
+  {
+    return Dali::Toolkit::Text::PlaceHolder::Property::TEXT;
+  }
+  else if(key.stringKey == PLACEHOLDER_TEXT_FOCUSED)
+  {
+    return Dali::Toolkit::Text::PlaceHolder::Property::TEXT_FOCUSED;
+  }
+  else if(key.stringKey == PLACEHOLDER_COLOR)
+  {
+    return Dali::Toolkit::Text::PlaceHolder::Property::COLOR;
+  }
+  else if(key.stringKey == PLACEHOLDER_FONT_FAMILY)
+  {
+    return Dali::Toolkit::Text::PlaceHolder::Property::FONT_FAMILY;
+  }
+  else if(key.stringKey == PLACEHOLDER_FONT_STYLE)
+  {
+    return Dali::Toolkit::Text::PlaceHolder::Property::FONT_STYLE;
+  }
+  else if(key.stringKey == PLACEHOLDER_POINT_SIZE)
+  {
+    return Dali::Toolkit::Text::PlaceHolder::Property::POINT_SIZE;
+  }
+  else if(key.stringKey == PLACEHOLDER_PIXEL_SIZE)
+  {
+    return Dali::Toolkit::Text::PlaceHolder::Property::PIXEL_SIZE;
+  }
+  else if(key.stringKey == PLACEHOLDER_ELLIPSIS)
+  {
+    return Dali::Toolkit::Text::PlaceHolder::Property::ELLIPSIS;
+  }
+
+  return Dali::Property::INVALID_INDEX;
+}
+
 } // namespace
 
 namespace Dali
@@ -344,64 +392,76 @@ void Controller::PlaceholderHandler::SetPlaceholderProperty(Controller& controll
 
   for(Property::Map::SizeType position = 0; position < count; ++position)
   {
-    KeyValuePair     keyValue = map.GetKeyValue(position);
-    Property::Key&   key      = keyValue.first;
-    Property::Value& value    = keyValue.second;
+    const KeyValuePair&    keyValue = map.GetKeyValue(position);
+    const Property::Key&   key      = keyValue.first;
+    const Property::Value& value    = keyValue.second;
 
-    if(key == Toolkit::Text::PlaceHolder::Property::TEXT || key == PLACEHOLDER_TEXT)
-    {
-      std::string text = "";
-      value.Get(text);
-      SetPlaceholderText(controller, Controller::PLACEHOLDER_TYPE_INACTIVE, text);
-    }
-    else if(key == Toolkit::Text::PlaceHolder::Property::TEXT_FOCUSED || key == PLACEHOLDER_TEXT_FOCUSED)
-    {
-      std::string text = "";
-      value.Get(text);
-      SetPlaceholderText(controller, Controller::PLACEHOLDER_TYPE_ACTIVE, text);
-    }
-    else if(key == Toolkit::Text::PlaceHolder::Property::COLOR || key == PLACEHOLDER_COLOR)
+    Property::Index indexKey = GetIntKey(key);
+
+    switch(indexKey)
     {
-      Vector4 textColor;
-      value.Get(textColor);
-      if(GetPlaceholderTextColor(controller) != textColor)
+      case Toolkit::Text::PlaceHolder::Property::TEXT:
+      case Toolkit::Text::PlaceHolder::Property::TEXT_FOCUSED:
       {
-        SetPlaceholderTextColor(controller, textColor);
+        PlaceholderType placeHolderType = (indexKey == PlaceHolder::Property::TEXT) ? Controller::PLACEHOLDER_TYPE_INACTIVE : Controller::PLACEHOLDER_TYPE_ACTIVE;
+
+        std::string text = "";
+        if(value.Get(text))
+        {
+          SetPlaceholderText(controller, placeHolderType, text);
+        }
+        break;
       }
-    }
-    else if(key == Toolkit::Text::PlaceHolder::Property::FONT_FAMILY || key == PLACEHOLDER_FONT_FAMILY)
-    {
-      std::string fontFamily = "";
-      value.Get(fontFamily);
-      SetPlaceholderFontFamily(controller, fontFamily);
-    }
-    else if(key == Toolkit::Text::PlaceHolder::Property::FONT_STYLE || key == PLACEHOLDER_FONT_STYLE)
-    {
-      SetFontStyleProperty(&controller, value, Text::FontStyle::PLACEHOLDER);
-    }
-    else if(key == Toolkit::Text::PlaceHolder::Property::POINT_SIZE || key == PLACEHOLDER_POINT_SIZE)
-    {
-      float pointSize;
-      value.Get(pointSize);
-      if(!Equals(GetPlaceholderTextFontSize(controller, Text::Controller::POINT_SIZE), pointSize))
+      case Toolkit::Text::PlaceHolder::Property::COLOR:
       {
-        SetPlaceholderTextFontSize(controller, pointSize, Text::Controller::POINT_SIZE);
+        Vector4 textColor;
+        if(value.Get(textColor))
+        {
+          if(GetPlaceholderTextColor(controller) != textColor)
+          {
+            SetPlaceholderTextColor(controller, textColor);
+          }
+        }
+        break;
       }
-    }
-    else if(key == Toolkit::Text::PlaceHolder::Property::PIXEL_SIZE || key == PLACEHOLDER_PIXEL_SIZE)
-    {
-      float pixelSize;
-      value.Get(pixelSize);
-      if(!Equals(GetPlaceholderTextFontSize(controller, Text::Controller::PIXEL_SIZE), pixelSize))
+      case Toolkit::Text::PlaceHolder::Property::FONT_FAMILY:
       {
-        SetPlaceholderTextFontSize(controller, pixelSize, Text::Controller::PIXEL_SIZE);
+        std::string fontFamily = "";
+        if(value.Get(fontFamily))
+        {
+          SetPlaceholderFontFamily(controller, fontFamily);
+        }
+        break;
+      }
+      case Toolkit::Text::PlaceHolder::Property::FONT_STYLE:
+      {
+        SetFontStyleProperty(&controller, value, Text::FontStyle::PLACEHOLDER);
+        break;
+      }
+      case Toolkit::Text::PlaceHolder::Property::POINT_SIZE:
+      case Toolkit::Text::PlaceHolder::Property::PIXEL_SIZE:
+      {
+        FontSizeType fontSizeType = (indexKey == PlaceHolder::Property::POINT_SIZE) ? Text::Controller::POINT_SIZE : Text::Controller::PIXEL_SIZE;
+
+        float fontSizeValue = 0.0f;
+        if(value.Get(fontSizeValue))
+        {
+          if(!Equals(GetPlaceholderTextFontSize(controller, fontSizeType), fontSizeValue))
+          {
+            SetPlaceholderTextFontSize(controller, fontSizeValue, fontSizeType);
+          }
+        }
+        break;
+      }
+      case Toolkit::Text::PlaceHolder::Property::ELLIPSIS:
+      {
+        bool ellipsis = false;
+        if(value.Get(ellipsis))
+        {
+          SetPlaceholderTextElideEnabled(controller, ellipsis);
+        }
+        break;
       }
-    }
-    else if(key == Toolkit::Text::PlaceHolder::Property::ELLIPSIS || key == PLACEHOLDER_ELLIPSIS)
-    {
-      bool ellipsis;
-      value.Get(ellipsis);
-      SetPlaceholderTextElideEnabled(controller, ellipsis);
     }
   }
 }