Utils: Fix Coverity issues related to UNCAUGHT_EXCEPT
authorWook Song <wook16.song@samsung.com>
Mon, 24 Mar 2025 08:38:20 +0000 (17:38 +0900)
committer정예린/AI System팀(SR)/삼성전자 <yelini.jeong@samsung.com>
Mon, 24 Mar 2025 23:26:25 +0000 (08:26 +0900)
This patch fixes Coverity issues related to UNCAUGHT_EXCEPT in the
utilities.

Change-Id: I12e70843364e5664ee2d52f6ca605d36a93ab125
Signed-off-by: Wook Song <wook16.song@samsung.com>
utils/examples/model_share.cc
utils/trinity_test/stress_test.cc

index 7c0a0c6cd32a802ef5f41e4eca7e15fbfc9a2151..893d48a2f6f08abe1b903bef2d8125bdac9e9ad0 100644 (file)
@@ -57,7 +57,14 @@ compare (const char *golden_path, const char *data, uint64_t size) {
 
   std::vector<uint8_t> raw_data (data, data + size);
   std::vector<uint8_t> golden_data;
-  golden_data.reserve (size);
+
+  try {
+    golden_data.reserve (size);
+  } catch (...) {
+    std::cerr << "Failed to allocate memory for golden data\n";
+    return -1;
+  }
+
   golden_data.insert (golden_data.begin (), std::istreambuf_iterator<char> (ifs),
                       std::istreambuf_iterator<char> ());
 
index 3328006521685a8ae59c1103236491307f7520c7..1cc997ba1cd05629e9ac8bc96a103614c9d1dbb3 100644 (file)
@@ -410,7 +410,11 @@ StressTester::parseArgs (int argc, char** argv) {
         setPrintTime (true);
         break;
       case 'c':
-        setAsyncNum (optarg);
+        try {
+          setAsyncNum (optarg);
+        } catch (...) {
+          goto err_getopt;
+        }
         break;
       case '?':
         if (optopt == 's' || optopt == 'a' || optopt == 'i' || optopt == 'm' || optopt == 'f' ||