Catch std::length_error exception at oss.str() 99/320499/1
authorEunki, Hong <eunkiki.hong@samsung.com>
Tue, 4 Mar 2025 08:23:40 +0000 (17:23 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Tue, 4 Mar 2025 08:25:35 +0000 (17:25 +0900)
Since we could call PrintSystemError API at destructor,
we should not throw exception whenever we could.

It might be false-positive usually.
But also, we need to ignore the future of false-positive coverity alarm.

Change-Id: I9e316d26e713cf65774d10d99e70de6f0bc7de09
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
dali/internal/system/generic/system-error-print-generic.cpp

index 1081382f4d32a325d02a2d34a39a89ef4921fb26..5c0e1e13bc0a0985fa37ebf33cf890e708bc645a 100644 (file)
@@ -54,30 +54,37 @@ std::string ConvertResultToString(int /* not used */, const char* errorName)
 
 void PrintSystemError(const char* fileName, const char* functionName, const int lineNumber)
 {
-  std::ostringstream oss;
+  try
+  {
+    std::ostringstream oss;
 
-  const static int         errorMessageMaxLength               = 128;
-  thread_local static char errorMessage[errorMessageMaxLength] = {}; // Initialze as null.
+    const static int         errorMessageMaxLength               = 128;
+    thread_local static char errorMessage[errorMessageMaxLength] = {}; // Initialze as null.
 
-  int copiedErrorNumber = errno;
+    int copiedErrorNumber = errno;
 
-  auto reternValue = strerror_r(copiedErrorNumber, errorMessage, errorMessageMaxLength - 1);
+    auto reternValue = strerror_r(copiedErrorNumber, errorMessage, errorMessageMaxLength - 1);
 
-  if(DALI_LIKELY(fileName))
-  {
-    oss << fileName << ": ";
+    if(DALI_LIKELY(fileName))
+    {
+      oss << fileName << ": ";
+    }
+    if(DALI_LIKELY(functionName))
+    {
+      oss << functionName << "";
+    }
+    oss << "(" << lineNumber << ") > ";
+
+    oss << "errno [" << copiedErrorNumber << "] ";
+    oss << ConvertResultToString(reternValue, static_cast<const char*>(&errorMessage[0])) << "\n";
+
+    std::string message = oss.str();
+    LogMessage(Dali::Integration::Log::DebugPriority::ERROR, message);
   }
-  if(DALI_LIKELY(functionName))
+  catch(const std::length_error& e)
   {
-    oss << functionName << "";
+    DALI_LOG_ERROR("length_error exception caught: %s", e.what());
   }
-  oss << "(" << lineNumber << ") > ";
-
-  oss << "errno [" << copiedErrorNumber << "] ";
-  oss << ConvertResultToString(reternValue, static_cast<const char*>(&errorMessage[0])) << "\n";
-
-  std::string message = oss.str();
-  LogMessage(Dali::Integration::Log::DebugPriority::ERROR, message);
 }
 
 } // namespace TizenPlatform