[Coverity] resolve coverity issues
authorDonghyeon Jeong <dhyeon.jeong@samsung.com>
Thu, 6 Feb 2025 08:12:21 +0000 (17:12 +0900)
committerjijoong.moon <jijoong.moon@samsung.com>
Tue, 11 Feb 2025 05:44:52 +0000 (14:44 +0900)
This pull request aims to resolve various Coverity issues.
The following warning group IDs are addressed:

Warning Group ID
- #1832819
- #1833528
- #1834338
- #1837520
- #1839030
- #1841393
- #1837925
- #1838882
- #1839129
- #1839950
- #1840581
- #1840832

**Self-evaluation:**
1. Build test: [X]Passed [ ]Failed [ ]Skipped
2. Run test:   [X]Passed [ ]Failed [ ]Skipped

Change-Id: I74a843793789b60c476d831bd53ce085e69cd163
Signed-off-by: Donghyeon Jeong <dhyeon.jeong@samsung.com>
nntrainer/app_context.cpp
nntrainer/models/neuralnet.cpp
nntrainer/tensor/memory_data.h

index cd398f0d116a4b157dbebfff353b3a4832af7ae3..8ef60b401efeb64e737c8b8aa9f96b91b1ab3f79 100644 (file)
@@ -385,7 +385,14 @@ AppContext &AppContext::Global() {
   /// in g++ there is a bug that hangs up if caller throws,
   /// so registerer is noexcept although it'd better not
   /// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70298
-  std::call_once(global_app_context_init_flag, registerer, std::ref(instance));
+  try {
+    std::call_once(global_app_context_init_flag, registerer,
+                   std::ref(instance));
+  } catch (std::exception &e) {
+    ml_loge("AppContext::Global() failed, reason: %s", e.what());
+  } catch (...) {
+    ml_loge("AppContext::Global() failed due to unknown reason");
+  }
   return instance;
 }
 
index 0abf3ab1785ff8a7845ebd02199ba16529a4c861..35a2da99f49674a72842d79e18de0e054fbb10f2 100644 (file)
@@ -80,7 +80,7 @@ NeuralNetwork::NeuralNetwork() :
   initialized(false),
   compiled(false),
   loadedFromConfig(false) {
-  app_context = AppContext(AppContext::Global());
+  app_context = AppContext::Global();
 }
 
 NeuralNetwork::NeuralNetwork(AppContext app_context_) :
index 834d3514e531beb3848f81c9b29fb7287c5922df..064493937f703a2599126b91d643c9a9d46edef5 100644 (file)
@@ -89,7 +89,8 @@ public:
   void validate() {
     if (valid)
       return;
-    validate_cb(id);
+    if (validate_cb != nullptr)
+      validate_cb(id);
   }
 
   /**
@@ -98,7 +99,8 @@ public:
   void invalidate() {
     if (!valid)
       return;
-    invalidate_cb(id);
+    if (invalidate_cb != nullptr)
+      invalidate_cb(id);
   }
 
   /**