From: Eunki, Hong Date: Thu, 1 Feb 2024 11:28:08 +0000 (+0900) Subject: [Tizen] Fix INTEGER_OVERFLOW coverity issues X-Git-Tag: accepted/tizen/8.0/unified/20240220.144347^2~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fe85f27b04e1a5b276fc29a0a510edb080e12bf6;p=platform%2Fcore%2Fuifw%2Fdali-core.git [Tizen] Fix INTEGER_OVERFLOW coverity issues - LinearConstraint : min value could be zero. We should branch out that case. - Render::Geometry : The number of indecies could be zero. - BaseSignal : Callback might be nullptr (even if we don't allow this cases) - Program : we might fail to find '[' keyword. Change-Id: I45c3fe567e98973d2a215b975f8094b7222995a8 Signed-off-by: Eunki, Hong --- diff --git a/automated-tests/src/dali/utc-Dali-Constrainer.cpp b/automated-tests/src/dali/utc-Dali-Constrainer.cpp index 63c4ee8..9d20aee 100644 --- a/automated-tests/src/dali/utc-Dali-Constrainer.cpp +++ b/automated-tests/src/dali/utc-Dali-Constrainer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 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. @@ -105,6 +105,21 @@ static void SetupLinearConstrainerNonUniformProgress(Dali::LinearConstrainer& li linearConstrainer.SetProperty(Dali::LinearConstrainer::Property::PROGRESS, points); } +static void SetupLinearConstrainerNonUniformProgressNonStartWithZero(Dali::LinearConstrainer& linearConstrainer) +{ + Dali::Property::Array points; + points.Resize(3); + points[0] = 0.0f; + points[1] = 1.0f; + points[2] = 0.0f; + linearConstrainer.SetProperty(Dali::LinearConstrainer::Property::VALUE, points); + + points[0] = 0.5f; + points[1] = 0.75f; + points[2] = 1.0f; + linearConstrainer.SetProperty(Dali::LinearConstrainer::Property::PROGRESS, points); +} + } // anonymous namespace //PathConstrainer test cases @@ -480,7 +495,7 @@ int UtcLinearConstrainerMoveAssignment(void) END_TEST; } -int UtcLinearConstrainerApply(void) +int UtcLinearConstrainerApply01(void) { TestApplication application; @@ -554,6 +569,34 @@ int UtcLinearConstrainerApply(void) application.Render(static_cast(durationSeconds * 250.0f) /* beyond the animation duration*/); DALI_TEST_EQUALS(actor.GetCurrentProperty(Dali::Actor::Property::POSITION).x, 0.0f, TEST_LOCATION); + //Setup a LinearConstrainer specifying the progress for each value which is not start with 0.0f + linearConstrainer.Remove(actor); + SetupLinearConstrainerNonUniformProgressNonStartWithZero(linearConstrainer); + linearConstrainer.Apply(Property(actor, Dali::Actor::Property::POSITION_X), Property(actor, index), range); + + actor.SetProperty(index, 0.0f); + animation.Play(); + application.SendNotification(); + application.Render(static_cast(durationSeconds * 250.0f) /* 25% progress */); + + DALI_TEST_EQUALS(actor.GetCurrentProperty(Dali::Actor::Property::POSITION).x, 0.0f, TEST_LOCATION); + + application.SendNotification(); + application.Render(static_cast(durationSeconds * 250.0f) /* 50% progress */); + DALI_TEST_EQUALS(actor.GetCurrentProperty(Dali::Actor::Property::POSITION).x, 0.0f, Math::MACHINE_EPSILON_1, TEST_LOCATION); + + application.SendNotification(); + application.Render(static_cast(durationSeconds * 250.0f) /* 75% progress */); + DALI_TEST_EQUALS(actor.GetCurrentProperty(Dali::Actor::Property::POSITION).x, 1.0f, Math::MACHINE_EPSILON_1, TEST_LOCATION); + + application.SendNotification(); + application.Render(static_cast(durationSeconds * 250.0f) /* 100% progress */); + DALI_TEST_EQUALS(actor.GetCurrentProperty(Dali::Actor::Property::POSITION).x, 0.0f, TEST_LOCATION); + + application.SendNotification(); + application.Render(static_cast(durationSeconds * 250.0f) /* beyond the animation duration*/); + DALI_TEST_EQUALS(actor.GetCurrentProperty(Dali::Actor::Property::POSITION).x, 0.0f, TEST_LOCATION); + END_TEST; } diff --git a/dali/internal/event/animation/linear-constrainer-impl.h b/dali/internal/event/animation/linear-constrainer-impl.h index 96222d3..3aaf18f 100644 --- a/dali/internal/event/animation/linear-constrainer-impl.h +++ b/dali/internal/event/animation/linear-constrainer-impl.h @@ -2,7 +2,7 @@ #define DALI_INTERNAL_LINEAR_CONSTRAINER_H /* - * 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. @@ -114,16 +114,21 @@ struct LinearConstraintFunctor min++; } - min--; - max = min + 1; + max = min; - if(min >= valueCount - 1) + if(min >= valueCount) { min = max = valueCount - 1; tLocal = 0.0f; } + else if(min == 0u) + { + min = max = 0u; + tLocal = 0.0f; + } else { + min--; tLocal = (t - mProgress[min]) / (mProgress[max] - mProgress[min]); } } diff --git a/dali/internal/render/renderers/render-geometry.cpp b/dali/internal/render/renderers/render-geometry.cpp index adab748..2b4c367 100644 --- a/dali/internal/render/renderers/render-geometry.cpp +++ b/dali/internal/render/renderers/render-geometry.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. @@ -201,7 +201,7 @@ bool Geometry::Draw( if(elementBufferOffset != 0u) { - elementBufferOffset = (elementBufferOffset >= numIndices) ? numIndices - 1 : elementBufferOffset; + elementBufferOffset = (elementBufferOffset >= numIndices) ? numIndices : elementBufferOffset; firstIndexOffset = intptr_t(elementBufferOffset * sizeOfIndex); numIndices -= elementBufferOffset; } @@ -215,14 +215,18 @@ bool Geometry::Draw( //Draw call if(mIndexBuffer && mGeometryType != Dali::Geometry::POINTS) { - //Indexed draw call - const Graphics::Buffer* ibo = mIndexBuffer->GetGraphicsObject(); - if(ibo) + // Issue draw call only if there's non-zero numIndices + if(numIndices) { - commandBuffer.BindIndexBuffer(*ibo, 0, mIndexType); - } + //Indexed draw call + const Graphics::Buffer* ibo = mIndexBuffer->GetGraphicsObject(); + if(ibo) + { + commandBuffer.BindIndexBuffer(*ibo, 0, mIndexType); + } - commandBuffer.DrawIndexed(numIndices, instanceCount, firstIndexOffset, 0, 0); + commandBuffer.DrawIndexed(numIndices, instanceCount, firstIndexOffset, 0, 0); + } } else { diff --git a/dali/internal/render/shaders/program.cpp b/dali/internal/render/shaders/program.cpp index 7ee3aa9..c149767 100644 --- a/dali/internal/render/shaders/program.cpp +++ b/dali/internal/render/shaders/program.cpp @@ -229,10 +229,13 @@ bool Program::GetUniform(const std::string_view& name, Hash hashedName, Hash has if(!name.empty() && name.back() == ']') { - hash = hashedNameNoArray; - auto pos = name.rfind("["); - match = name.substr(0, pos); // Remove subscript - arrayIndex = atoi(&name[pos + 1]); + auto pos = name.rfind("["); + if(pos != std::string::npos) + { + hash = hashedNameNoArray; + match = name.substr(0, pos); // Remove subscript + arrayIndex = atoi(&name[pos + 1]); + } } for(const ReflectionUniformInfo& item : mReflection) diff --git a/dali/public-api/signals/base-signal.cpp b/dali/public-api/signals/base-signal.cpp index 0729fab..b61df3d 100644 --- a/dali/public-api/signals/base-signal.cpp +++ b/dali/public-api/signals/base-signal.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. @@ -215,7 +215,7 @@ std::list::iterator BaseSignal::FindCallback(CallbackBase* cal { const auto& iter = convertorIter->second; // std::list::iterator - if(*iter) // the value of iterator can be null. + if(*iter && iter->GetCallback()) // the value of iterator can be null. { if(*(iter->GetCallback()) == *callback) {