From ec945b375af7d225a1dd917ec51d4118fbb94822 Mon Sep 17 00:00:00 2001 From: "Eunki, Hong" Date: Mon, 18 Mar 2024 14:29:36 +0900 Subject: [PATCH] Fix svace issue phase2 : Need to check Property::Value.Get() return 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 --- .../src/dali-toolkit/utc-Dali-TableView.cpp | 48 ++++++++++++++--- dali-toolkit/internal/builder/builder-impl.cpp | 15 +++--- .../controls/buttons/toggle-button-impl.cpp | 17 ++++-- .../super-blur-view/super-blur-view-impl.cpp | 27 +++++----- .../controls/table-view/table-view-impl.cpp | 61 ++++++++++++++-------- dali-toolkit/internal/controls/tooltip/tooltip.cpp | 8 +-- 6 files changed, 121 insertions(+), 55 deletions(-) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TableView.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TableView.cpp index 212f45e..5ec6b5f 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TableView.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TableView.cpp @@ -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() == 4); + DALI_TEST_CHECK(tableView.GetRows() == 7u); + DALI_TEST_CHECK(tableView.GetProperty(TableView::Property::ROWS).Get() == 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() == 5); + DALI_TEST_CHECK(tableView.GetColumns() == 8u); + DALI_TEST_CHECK(tableView.GetProperty(TableView::Property::COLUMNS).Get() == 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().compare("relative") == 0); DALI_TEST_EQUALS(childMap->Find("value")->Get(), 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().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().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(); + DALI_TEST_CHECK(layoutColumnsGet.GetKey(2).compare(layoutColumns.GetKey(0)) == 0); childMap = layoutColumnsGet.GetValue(2).GetMap(); DALI_TEST_CHECK(childMap->Find("policy")->Get().compare("relative") == 0); DALI_TEST_EQUALS(childMap->Find("value")->Get(), 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().compare("fixed") == 0); DALI_TEST_EQUALS(childMap->Find("value")->Get(), 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().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().compare("fill") == 0); + END_TEST; } diff --git a/dali-toolkit/internal/builder/builder-impl.cpp b/dali-toolkit/internal/builder/builder-impl.cpp index 8b69071..08c8bb9 100644 --- a/dali-toolkit/internal/builder/builder-impl.cpp +++ b/dali-toolkit/internal/builder/builder-impl.cpp @@ -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; + } } } } diff --git a/dali-toolkit/internal/controls/buttons/toggle-button-impl.cpp b/dali-toolkit/internal/controls/buttons/toggle-button-impl.cpp index ef56202..deab292 100644 --- a/dali-toolkit/internal/controls/buttons/toggle-button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/toggle-button-impl.cpp @@ -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 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; } diff --git a/dali-toolkit/internal/controls/super-blur-view/super-blur-view-impl.cpp b/dali-toolkit/internal/controls/super-blur-view/super-blur-view-impl.cpp index 907e7e0..4aedfc0 100644 --- a/dali-toolkit/internal/controls/super-blur-view/super-blur-view-impl.cpp +++ b/dali-toolkit/internal/controls/super-blur-view/super-blur-view-impl.cpp @@ -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"); + } } } } diff --git a/dali-toolkit/internal/controls/table-view/table-view-impl.cpp b/dali-toolkit/internal/controls/table-view/table-view-impl.cpp index d75d100..686c1ca 100644 --- a/dali-toolkit/internal/controls/table-view/table-view-impl.cpp +++ b/dali-toolkit/internal/controls/table-view/table-view-impl.cpp @@ -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(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(policyValue.c_str(), + LAYOUT_POLICY_STRING_TABLE, + LAYOUT_POLICY_STRING_TABLE_COUNT, + policy)) { - (tableViewImpl.*funcFixed)(index, childMapValue->Get()); - } - else if(policy == Toolkit::TableView::RELATIVE) - { - (tableViewImpl.*funcRelative)(index, childMapValue->Get()); - } - 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 } } } diff --git a/dali-toolkit/internal/controls/tooltip/tooltip.cpp b/dali-toolkit/internal/controls/tooltip/tooltip.cpp index 1b4c749..687d3ef 100644 --- a/dali-toolkit/internal/controls/tooltip/tooltip.cpp +++ b/dali-toolkit/internal/controls/tooltip/tooltip.cpp @@ -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) { -- 2.7.4