Fix static analysis issues 29/289729/1
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 14 Mar 2023 05:21:53 +0000 (05:21 +0000)
committerHwankyu Jhun <h.jhun@samsung.com>
Tue, 14 Mar 2023 05:21:53 +0000 (05:21 +0000)
Types:
 - Uninitialized pointer read

Change-Id: Ibb40848fcd278ff28216b7c2a41091a95e4d3b8c
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/launchpad-process-pool/launchpad.cc

index 3699acb..9917e05 100644 (file)
@@ -93,47 +93,47 @@ enum candidate_process_state_e {
 };
 
 typedef struct {
-  int type;
-  bool prepared;
-  int pid; /* for hydra this pid is not the pid of hydra itself */
+  int type = -1;
+  bool prepared = false;
+  int pid = CANDIDATE_NONE; /* for hydra this pid is not the pid of hydra itself */
   /* but pid of non-hydra candidate, which was forked from hydra */
-  int hydra_pid;
-  int loader_id;
-  int caller_pid;
-  int send_fd;
-  int hydra_fd;
-  int last_exec_time;
-  guint timer;
-  char* loader_name;
-  char* loader_path;
-  char* loader_extra;
-  int detection_method;
-  int timeout_val;
-  unsigned long long cpu_total_time;
-  unsigned long long cpu_idle_time;
-  int threshold;
-  int threshold_max;
-  int threshold_min;
-  int cur_event;
-  bool on_boot;
-  bool app_exists;
-  bool touched;
-  int activation_method;
-  int deactivation_method;
-  unsigned int ttl;
-  guint live_timer;
-  int state;
-  bool is_hydra;
-  bool app_check;
-  io_channel_h client_channel;
-  io_channel_h channel;
-  io_channel_h hydra_channel;
-  unsigned int score;
-  unsigned int pss;
-  int cpu_check_count;
-  int on_boot_timeout;
-  guint on_boot_timer;
-  int sched_priority;
+  int hydra_pid = CANDIDATE_NONE;
+  int loader_id = -1;
+  int caller_pid = CANDIDATE_NONE;
+  int send_fd = -1;
+  int hydra_fd = -1;
+  int last_exec_time = 0;
+  guint timer = 0;
+  char* loader_name = nullptr;
+  char* loader_path = nullptr;
+  char* loader_extra = nullptr;
+  int detection_method = 0;
+  int timeout_val = 0;
+  unsigned long long cpu_total_time = 0;
+  unsigned long long cpu_idle_time = 0;
+  int threshold = 0;
+  int threshold_max = 0;
+  int threshold_min = 0;
+  int cur_event = 0;
+  bool on_boot = false;
+  bool app_exists = false;
+  bool touched = false;
+  int activation_method = 0;
+  int deactivation_method = 0;
+  unsigned int ttl = 0;
+  guint live_timer = 0;
+  int state = 0;
+  bool is_hydra = false;
+  bool app_check = false;
+  io_channel_h client_channel = nullptr;
+  io_channel_h channel = nullptr;
+  io_channel_h hydra_channel = nullptr;
+  unsigned int score = 0;
+  unsigned int pss = 0;
+  int cpu_check_count = 0;
+  int on_boot_timeout = 0;
+  guint on_boot_timer = 0;
+  int sched_priority = 0;
   std::vector<std::string> condition_path_exists;
 } candidate_process_context_t;
 
@@ -2599,7 +2599,8 @@ static bool __handle_launch_event(int fd, io_condition_e cond, void* data) {
     }
   }
 
-  if (request->cmd < 0 || request->cmd >= ARRAY_SIZE(__request_handlers) ||
+  if (request->cmd < 0 ||
+      static_cast<size_t>(request->cmd) >= ARRAY_SIZE(__request_handlers) ||
       __request_handlers[request->cmd] == nullptr) {
     _E("Unknown command: %d", request->cmd);
     __request_send_result(request, -EINVAL);