Fix svace issue when TJ_SUBSAMP is bigger than 7 43/303943/4
authorEunki, Hong <eunkiki.hong@samsung.com>
Mon, 8 Jan 2024 08:31:17 +0000 (17:31 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Mon, 8 Jan 2024 14:28:29 +0000 (23:28 +0900)
It is possible that TJ_SUBSAMPL could be greater than 7 in future.

This patch make ensure that it will works well even that value increased.

Change-Id: I3a7b1ce25cda3fb6717f3cb847bd0d4e744086e7
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
dali/internal/imaging/common/loader-jpeg-turbo.cpp

index cf1bcb91f0bf2e0e4af140258b607e0146b86617..7a7f42b8fc4783d648f37d5b0b49183aed3db61b 100644 (file)
@@ -59,6 +59,8 @@ const char* CHROMINANCE_SUBSAMPLING_OPTIONS_ENV[] = {"DALI_ENABLE_DECODE_JPEG_TO
                                                      "DALI_ENABLE_DECODE_JPEG_TO_YUV_411",
                                                      "DALI_ENABLE_DECODE_JPEG_TO_YUV_441"};
 
+const int CHROMINANCE_SUBSAMPLING_OPTIONS_ENV_COUNT = sizeof(CHROMINANCE_SUBSAMPLING_OPTIONS_ENV) / sizeof(CHROMINANCE_SUBSAMPLING_OPTIONS_ENV[0]);
+
 static bool gSubsamplingFormatTable[TJ_NUMSAMP] = {
   false,
 };
@@ -94,14 +96,20 @@ static bool IsSubsamplingFormatEnabled(int chrominanceSubsampling)
   {
     for(int i = 0; i < TJ_NUMSAMP; i++)
     {
-      auto valueString           = Dali::EnvironmentVariable::GetEnvironmentVariable(CHROMINANCE_SUBSAMPLING_OPTIONS_ENV[i]);
+      const char* envName        = DALI_LIKELY(i < CHROMINANCE_SUBSAMPLING_OPTIONS_ENV_COUNT) ? CHROMINANCE_SUBSAMPLING_OPTIONS_ENV[i] : "";
+      auto        valueString    = Dali::EnvironmentVariable::GetEnvironmentVariable(envName);
       gSubsamplingFormatTable[i] = valueString ? std::atoi(valueString) : false;
     }
 
     gIsSubsamplingFormatTableInitialized = true;
   }
 
-  return gSubsamplingFormatTable[chrominanceSubsampling];
+  if(DALI_UNLIKELY(chrominanceSubsampling >= TJ_NUMSAMP))
+  {
+    DALI_LOG_WARNING("WARNING! Input subsampling value [%d] is bigger than turbojpeg library support [%d]\n", chrominanceSubsampling, TJ_NUMSAMP);
+  }
+
+  return chrominanceSubsampling < TJ_NUMSAMP ? gSubsamplingFormatTable[chrominanceSubsampling] : false;
 }
 
 /**
@@ -203,7 +211,7 @@ public:
   }
 
   /// @brief Pointer to Pointer cast operator
-  operator T* *()
+  operator T**()
   {
     return &mRawPointer;
   }