Fix svace issue phase2 : Need to check Property::Value.Get() return 11/308111/1
authorEunki, Hong <eunkiki.hong@samsung.com>
Mon, 18 Mar 2024 05:29:36 +0000 (14:29 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Mon, 18 Mar 2024 06:19:08 +0000 (15:19 +0900)
It is possible that user set invalid value type.

If then, we need to skip given value setter.

Change-Id: I1d3074c6bf7ee061cb195195a90f8b07fe04db7f
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
automated-tests/src/dali-toolkit/utc-Dali-TableView.cpp
dali-toolkit/internal/builder/builder-impl.cpp
dali-toolkit/internal/controls/buttons/toggle-button-impl.cpp
dali-toolkit/internal/controls/super-blur-view/super-blur-view-impl.cpp
dali-toolkit/internal/controls/table-view/table-view-impl.cpp
dali-toolkit/internal/controls/tooltip/tooltip.cpp

index 212f45e..5ec6b5f 100644 (file)
@@ -611,18 +611,18 @@ int UtcDaliTableViewSetGetProperty(void)
   // Test "rows" property
   DALI_TEST_CHECK(tableView.GetPropertyIndex(PROPERTY_NAME_ROWS) == TableView::Property::ROWS);
 
-  tableView.SetProperty(TableView::Property::ROWS, 4);
+  tableView.SetProperty(TableView::Property::ROWS, 7);
 
-  DALI_TEST_CHECK(tableView.GetRows() == 4u);
-  DALI_TEST_CHECK(tableView.GetProperty(TableView::Property::ROWS).Get<int>() == 4);
+  DALI_TEST_CHECK(tableView.GetRows() == 7u);
+  DALI_TEST_CHECK(tableView.GetProperty(TableView::Property::ROWS).Get<int>() == 7);
 
   // Test "columns" property
   DALI_TEST_CHECK(tableView.GetPropertyIndex(PROPERTY_NAME_COLUMNS) == TableView::Property::COLUMNS);
 
-  tableView.SetProperty(TableView::Property::COLUMNS, 5);
+  tableView.SetProperty(TableView::Property::COLUMNS, 8);
 
-  DALI_TEST_CHECK(tableView.GetColumns() == 5u);
-  DALI_TEST_CHECK(tableView.GetProperty(TableView::Property::COLUMNS).Get<int>() == 5);
+  DALI_TEST_CHECK(tableView.GetColumns() == 8u);
+  DALI_TEST_CHECK(tableView.GetProperty(TableView::Property::COLUMNS).Get<int>() == 8);
 
   // Test "cellPadding" property
   DALI_TEST_CHECK(tableView.GetPropertyIndex(PROPERTY_NAME_CELL_PADDING) == TableView::Property::CELL_PADDING);
@@ -640,6 +640,12 @@ int UtcDaliTableViewSetGetProperty(void)
   Property::Map item2;
   item2["policy"] = "relative";
   item2["value"]  = 0.2f;
+  //{ "policy": "fill"},
+  Property::Map item3;
+  item3["policy"] = "fill";
+  //{ "policy": "fit"},
+  Property::Map item4;
+  item4["policy"] = "fit";
 
   // Test "layoutRows" property
   DALI_TEST_CHECK(tableView.GetPropertyIndex(PROPERTY_NAME_LAYOUT_ROWS) == TableView::Property::LAYOUT_ROWS);
@@ -648,12 +654,16 @@ int UtcDaliTableViewSetGetProperty(void)
    * "layoutRows":
    *  {
    *    "1": { "policy": "fixed", "value": 30 },
-   *    "3": { "policy": "relative", "value": 0.2 }
+   *    "3": { "policy": "relative", "value": 0.2 },
+   *    "4": { "policy": "fill" },
+   *    "6": { "policy": "fit" },
    *   }
    */
   Property::Map layoutRows;
   layoutRows["1"] = item1;
   layoutRows["3"] = item2;
+  layoutRows["4"] = item3;
+  layoutRows["6"] = item4;
   tableView.SetProperty(TableView::Property::LAYOUT_ROWS, layoutRows);
 
   DALI_TEST_EQUALS(tableView.GetFixedHeight(1u), 30.f, TEST_LOCATION);
@@ -671,6 +681,14 @@ int UtcDaliTableViewSetGetProperty(void)
   DALI_TEST_CHECK(childMap->Find("policy")->Get<std::string>().compare("relative") == 0);
   DALI_TEST_EQUALS(childMap->Find("value")->Get<float>(), 0.2f, TEST_LOCATION);
 
+  childMap = layoutRowsGet.GetValue(4).GetMap();
+  DALI_TEST_CHECK(layoutRowsGet.GetKey(4).compare(layoutRows.GetKey(2)) == 0);
+  DALI_TEST_CHECK(childMap->Find("policy")->Get<std::string>().compare("fill") == 0);
+
+  childMap = layoutRowsGet.GetValue(6).GetMap();
+  DALI_TEST_CHECK(layoutRowsGet.GetKey(6).compare(layoutRows.GetKey(3)) == 0);
+  DALI_TEST_CHECK(childMap->Find("policy")->Get<std::string>().compare("fit") == 0);
+
   // Test "layoutColumns" property
   DALI_TEST_CHECK(tableView.GetPropertyIndex(PROPERTY_NAME_LAYOUT_COLUMNS) == TableView::Property::LAYOUT_COLUMNS);
 
@@ -678,27 +696,41 @@ int UtcDaliTableViewSetGetProperty(void)
    * "layoutColumns":
    *  {
    *    "2": { "policy": "relative", "value": 0.2 },
-   *    "3": { "policy": "fixed", "value": 30 }
+   *    "3": { "policy": "fixed", "value": 30 },
+   *    "5": { "policy": "fit" },
+   *    "7": { "policy": "fill" }
    *   }
    */
   Property::Map layoutColumns;
   layoutColumns["2"] = item2;
   layoutColumns["3"] = item1;
+  layoutColumns["5"] = item4;
+  layoutColumns["7"] = item3;
   tableView.SetProperty(TableView::Property::LAYOUT_COLUMNS, layoutColumns);
 
   DALI_TEST_EQUALS(tableView.GetRelativeWidth(2u), 0.2f, TEST_LOCATION);
   DALI_TEST_EQUALS(tableView.GetFixedWidth(3u), 30.f, TEST_LOCATION);
 
   Property::Map layoutColumnsGet = tableView.GetProperty(TableView::Property::LAYOUT_COLUMNS).Get<Property::Map>();
+
   DALI_TEST_CHECK(layoutColumnsGet.GetKey(2).compare(layoutColumns.GetKey(0)) == 0);
   childMap = layoutColumnsGet.GetValue(2).GetMap();
   DALI_TEST_CHECK(childMap->Find("policy")->Get<std::string>().compare("relative") == 0);
   DALI_TEST_EQUALS(childMap->Find("value")->Get<float>(), 0.2f, TEST_LOCATION);
+
   childMap = layoutColumnsGet.GetValue(3).GetMap();
   DALI_TEST_CHECK(layoutColumnsGet.GetKey(3).compare(layoutColumns.GetKey(1)) == 0);
   DALI_TEST_CHECK(childMap->Find("policy")->Get<std::string>().compare("fixed") == 0);
   DALI_TEST_EQUALS(childMap->Find("value")->Get<float>(), 30.f, TEST_LOCATION);
 
+  childMap = layoutColumnsGet.GetValue(5).GetMap();
+  DALI_TEST_CHECK(layoutColumnsGet.GetKey(5).compare(layoutColumns.GetKey(2)) == 0);
+  DALI_TEST_CHECK(childMap->Find("policy")->Get<std::string>().compare("fit") == 0);
+
+  childMap = layoutColumnsGet.GetValue(7).GetMap();
+  DALI_TEST_CHECK(layoutColumnsGet.GetKey(7).compare(layoutColumns.GetKey(3)) == 0);
+  DALI_TEST_CHECK(childMap->Find("policy")->Get<std::string>().compare("fill") == 0);
+
   END_TEST;
 }
 
index 8b69071..08c8bb9 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.
@@ -773,7 +773,7 @@ void Builder::LoadConfiguration(const TreeNode& root, Property::Map& intoMap)
                 {
                   // If we find "{","}" pair but can't find matched constant
                   // try to find other "{","}" pair after current left position.
-                  pos = leftPos + 1;
+                  pos = rightPos + 1;
 
                   for(uint32_t i = 0; i < mReplacementMap.Count(); i++)
                   {
@@ -784,11 +784,12 @@ void Builder::LoadConfiguration(const TreeNode& root, Property::Map& intoMap)
                     if(0 == stringConfigValue.compare(leftPos + 1, rightPos - leftPos - 1, constant.stringKey))
                     {
                       std::string replaceString;
-                      mReplacementMap.GetValue(i).Get(replaceString);
-
-                      stringConfigValue.replace(leftPos, rightPos - leftPos + 1, replaceString);
-                      pos = leftPos + replaceString.size();
-                      break;
+                      if(DALI_LIKELY(mReplacementMap.GetValue(i).Get(replaceString)))
+                      {
+                        stringConfigValue.replace(leftPos, rightPos - leftPos + 1, replaceString);
+                        pos = leftPos + replaceString.size();
+                        break;
+                      }
                     }
                   }
                 }
index ef56202..deab292 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.
@@ -144,11 +144,22 @@ void ToggleButton::SetProperty(BaseObject* object, Property::Index propertyIndex
           std::vector<std::string> tips;
           size_t                   tipsCount = tipArray->Count();
           tips.resize(tipsCount);
+
+          bool valid = true;
           for(size_t i = 0; i != tipsCount; ++i)
           {
-            tipArray->GetElementAt(i).Get(tips[i]);
+            if(DALI_UNLIKELY(!tipArray->GetElementAt(i).Get(tips[i])))
+            {
+              // Given array is invalid. Fast out.
+              valid = false;
+              break;
+            }
+          }
+
+          if(DALI_LIKELY(valid))
+          {
+            toggleButtonImpl.SetToggleTooltips(tips);
           }
-          toggleButtonImpl.SetToggleTooltips(tips);
         }
         break;
       }
index 907e7e0..4aedfc0 100644 (file)
@@ -353,20 +353,21 @@ void SuperBlurView::SetProperty(BaseObject* object, Property::Index propertyInde
 
     if(propertyIndex == Toolkit::SuperBlurView::Property::IMAGE_URL)
     {
-      value.Get(superBlurViewImpl.mUrl);
-
-      PixelData pixels = SyncImageLoader::Load(superBlurViewImpl.mUrl);
-
-      if(pixels)
-      {
-        Texture texture = Texture::New(TextureType::TEXTURE_2D, pixels.GetPixelFormat(), pixels.GetWidth(), pixels.GetHeight());
-        texture.Upload(pixels, 0, 0, 0, 0, pixels.GetWidth(), pixels.GetHeight());
-
-        superBlurViewImpl.SetTexture(texture);
-      }
-      else
+      if(DALI_LIKELY(value.Get(superBlurViewImpl.mUrl)))
       {
-        DALI_LOG_ERROR("Cannot create image from property value\n");
+        PixelData pixels = SyncImageLoader::Load(superBlurViewImpl.mUrl);
+
+        if(pixels)
+        {
+          Texture texture = Texture::New(TextureType::TEXTURE_2D, pixels.GetPixelFormat(), pixels.GetWidth(), pixels.GetHeight());
+          texture.Upload(pixels, 0, 0, 0, 0, pixels.GetWidth(), pixels.GetHeight());
+
+          superBlurViewImpl.SetTexture(texture);
+        }
+        else
+        {
+          DALI_LOG_ERROR("Cannot create image from property value\n");
+        }
       }
     }
   }
index d75d100..686c1ca 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.
@@ -1224,31 +1224,50 @@ void TableView::SetHeightOrWidthProperty(TableView& tableViewImpl,
       std::istringstream(map->GetKey(i)) >> index;
       if(childMap)
       {
-        Property::Value* policy        = childMap->Find("policy");
-        Property::Value* childMapValue = childMap->Find("value");
-        if(policy && childMapValue)
+        Property::Value* policy = childMap->Find("policy");
+        if(policy)
         {
           std::string policyValue;
-          policy->Get(policyValue);
-          Toolkit::TableView::LayoutPolicy policy;
-          if(Scripting::GetEnumeration<Toolkit::TableView::LayoutPolicy>(policyValue.c_str(),
-                                                                         LAYOUT_POLICY_STRING_TABLE,
-                                                                         LAYOUT_POLICY_STRING_TABLE_COUNT,
-                                                                         policy))
+          if(DALI_LIKELY(policy->Get(policyValue)))
           {
-            if(policy == Toolkit::TableView::FIXED)
+            Toolkit::TableView::LayoutPolicy policy;
+            if(Scripting::GetEnumeration<Toolkit::TableView::LayoutPolicy>(policyValue.c_str(),
+                                                                           LAYOUT_POLICY_STRING_TABLE,
+                                                                           LAYOUT_POLICY_STRING_TABLE_COUNT,
+                                                                           policy))
             {
-              (tableViewImpl.*funcFixed)(index, childMapValue->Get<float>());
-            }
-            else if(policy == Toolkit::TableView::RELATIVE)
-            {
-              (tableViewImpl.*funcRelative)(index, childMapValue->Get<float>());
-            }
-            else if(policy == Toolkit::TableView::FIT)
-            {
-              (tableViewImpl.*funcFit)(index);
+              switch(policy)
+              {
+                case Toolkit::TableView::FIXED:
+                case Toolkit::TableView::RELATIVE:
+                {
+                  Property::Value* childMapValue = childMap->Find("value");
+                  float            childValue    = 0.0f;
+                  if(DALI_LIKELY(childMapValue && childMapValue->Get(childValue)))
+                  {
+                    if(policy == Toolkit::TableView::FIXED)
+                    {
+                      (tableViewImpl.*funcFixed)(index, childValue);
+                    }
+                    else // if(policy == Toolkit::TableView::RELATIVE)
+                    {
+                      (tableViewImpl.*funcRelative)(index, childValue);
+                    }
+                  }
+                  break;
+                }
+                case Toolkit::TableView::FIT:
+                {
+                  (tableViewImpl.*funcFit)(index);
+                  break;
+                }
+                default:
+                {
+                  // do nothing for FILL policy
+                  break;
+                }
+              }
             }
-            // do nothing for FILL policy
           }
         }
       }
index 1b4c749..687d3ef 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.
@@ -289,8 +289,10 @@ void Tooltip::SetBackground(const Property::Value& value)
 
   if(type == Property::STRING)
   {
-    value.Get(mBackgroundImage);
-    mBackgroundBorder.Set(0, 0, 0, 0);
+    if(DALI_LIKELY(value.Get(mBackgroundImage)))
+    {
+      mBackgroundBorder.Set(0, 0, 0, 0);
+    }
   }
   else if(type == Property::MAP)
   {