[Tizen] Fix INTEGER_OVERFLOW coverity issues 57/306257/1
authorEunki, Hong <eunkiki.hong@samsung.com>
Thu, 1 Feb 2024 11:28:08 +0000 (20:28 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Mon, 19 Feb 2024 08:11:52 +0000 (17:11 +0900)
 - 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 <eunkiki.hong@samsung.com>
automated-tests/src/dali/utc-Dali-Constrainer.cpp
dali/internal/event/animation/linear-constrainer-impl.h
dali/internal/render/renderers/render-geometry.cpp
dali/internal/render/shaders/program.cpp
dali/public-api/signals/base-signal.cpp

index 63c4ee8..9d20aee 100644 (file)
@@ -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<unsigned int>(durationSeconds * 250.0f) /* beyond the animation duration*/);
   DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(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<unsigned int>(durationSeconds * 250.0f) /* 25% progress */);
+
+  DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.0f, TEST_LOCATION);
+
+  application.SendNotification();
+  application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 50% progress */);
+  DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.0f, Math::MACHINE_EPSILON_1, TEST_LOCATION);
+
+  application.SendNotification();
+  application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 75% progress */);
+  DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 1.0f, Math::MACHINE_EPSILON_1, TEST_LOCATION);
+
+  application.SendNotification();
+  application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 100% progress */);
+  DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.0f, TEST_LOCATION);
+
+  application.SendNotification();
+  application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* beyond the animation duration*/);
+  DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.0f, TEST_LOCATION);
+
   END_TEST;
 }
 
index 96222d3..3aaf18f 100644 (file)
@@ -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]);
         }
       }
index adab748..2b4c367 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.
@@ -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
   {
index 7ee3aa9..c149767 100644 (file)
@@ -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)
index 0729fab..b61df3d 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.
@@ -215,7 +215,7 @@ std::list<SignalConnection>::iterator BaseSignal::FindCallback(CallbackBase* cal
   {
     const auto& iter = convertorIter->second; // std::list<SignalConnection>::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)
       {