utils/test: Fix issues reported by static analysis tools accepted/tizen/unified/20250319.072537 accepted/tizen/unified/x/20250319.090559
authorWook Song <wook16.song@samsung.com>
Wed, 12 Mar 2025 02:16:21 +0000 (11:16 +0900)
committerWook Song <wook16.song@samsung.com>
Tue, 18 Mar 2025 07:28:09 +0000 (16:28 +0900)
This patch fixes an SVACE issue (#256496) related to NO_CATCH and a
covertity issue (#1840314) related to Uncaught Exception in StressTest.

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

index d613cd6519e9c7df53b49eb343ef1b10d2ee882c..3328006521685a8ae59c1103236491307f7520c7 100644 (file)
@@ -8,6 +8,7 @@
  * @brief StressTest for alloc memory and inference for TRIV2 device
  * @bug No known bugs except for NYI items
  */
+#include <bits/stdc++.h>
 
 #include "stress_test.h"
 
@@ -369,13 +370,25 @@ StressTester::parseArgs (int argc, char** argv) {
   while ((c = getopt (argc, argv, "i:s:a:rm:f:pthc:")) != -1) {
     switch (c) {
       case 'i':
-        setIterNum (optarg);
+        try {
+          setIterNum (optarg);
+        } catch (...) {
+          goto err_getopt;
+        }
         break;
       case 's':
-        setBufferSize (optarg);
+        try {
+          setBufferSize (optarg);
+        } catch (...) {
+          goto err_getopt;
+        }
         break;
       case 'a':
-        setAllocNum (optarg);
+        try {
+          setAllocNum (optarg);
+        } catch (...) {
+          goto err_getopt;
+        }
         break;
       case 'r':
         setAllocRandom (true);
@@ -384,7 +397,11 @@ StressTester::parseArgs (int argc, char** argv) {
         setModelPath (optarg);
         break;
       case 'f':
-        setInferNum (optarg);
+        try {
+          setInferNum (optarg);
+        } catch (...) {
+          goto err_getopt;
+        }
         break;
       case 'p':
         setPauseOnIter (true);
@@ -408,6 +425,11 @@ StressTester::parseArgs (int argc, char** argv) {
     }
   }
   return 0;
+
+err_getopt:
+  std::cerr << "Invalid argument for option '" << static_cast<char> (c) << "' \n";
+  printUsage (argv[0]);
+  return -1;
 }
 
 int
@@ -426,7 +448,13 @@ main (int argc, char** argv) {
     return status;
   }
 
-  status = stressTester.run ();
+  try {
+    status = stressTester.run ();
+  } catch (const std::bad_function_call& e) {
+    std::cerr << "Exception occurred: " << e.what () << std::endl;
+    status = -1;
+  }
+
   if (status < 0) {
     std::cerr << "Failed to run" << std::endl;
     return status;