From 18b00a7cc7518a781638a7751523824d8578f3dc Mon Sep 17 00:00:00 2001 From: Suyeon Hwang Date: Thu, 6 Apr 2023 14:09:29 +0900 Subject: [PATCH] Rearrange the scope of each temporary variables This patch is for solving static analysis issues. Through this patch, the scope of each temporary variables will become as smaller as they can. This change can reduce the possibility of mistakes such as accessing invalid pointer. Change-Id: I93aaef1711ddc27663812fd0c089c9be4c277f23 Signed-off-by: Suyeon Hwang --- common/vc_cmd_db.c | 8 +++----- common/vc_command.c | 11 ++++------- server/vcd_client_data.c | 7 ++----- server/vcd_server.c | 13 ++++--------- 4 files changed, 13 insertions(+), 26 deletions(-) diff --git a/common/vc_cmd_db.c b/common/vc_cmd_db.c index 2ddbb47..9a30848 100644 --- a/common/vc_cmd_db.c +++ b/common/vc_cmd_db.c @@ -2172,12 +2172,10 @@ static int __vc_db_insert_command(sqlite3* db_handle, int pid, vc_cmd_type_e typ } if (0 != g_slist_length(cmd_list)) { - GSList *iter = NULL; - char* temp_command = NULL; - iter = g_slist_nth(cmd_list, 0); + GSList *iter = g_slist_nth(cmd_list, 0); while (NULL != iter) { - temp_command = iter->data; + char *temp_command = iter->data; if (NULL != temp_command) { if (NULL != tmp_cmd->command) { @@ -2219,7 +2217,7 @@ static int __vc_db_insert_command(sqlite3* db_handle, int pid, vc_cmd_type_e typ if (VC_DB_ERROR_NONE != ret) { while (NULL != iter) { - temp_command = iter->data; + char *temp_command = iter->data; if (NULL != temp_command) { cmd_list = g_slist_remove(cmd_list, temp_command); diff --git a/common/vc_command.c b/common/vc_command.c index 1c63b22..e6b5767 100644 --- a/common/vc_command.c +++ b/common/vc_command.c @@ -1763,8 +1763,6 @@ static int __vc_cmd_trelative_check(const char *str, struct tm *td, int *exist) int hour = -1; int min = -1; - char *tempstr = NULL; - *exist = 0; ret = regexec(®[3], str, 1, pmatch, 0); if (0 == ret) { @@ -1782,7 +1780,7 @@ static int __vc_cmd_trelative_check(const char *str, struct tm *td, int *exist) SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid string length"); return VC_ERROR_OPERATION_FAILED; } - tempstr = strndup(str + pmatch[1].rm_so, (size_t)len); + char *tempstr = strndup(str + pmatch[1].rm_so, (size_t)len); if (NULL == tempstr) { SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Memory allocation is failed"); @@ -1808,7 +1806,7 @@ static int __vc_cmd_trelative_check(const char *str, struct tm *td, int *exist) SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid string length"); return VC_ERROR_OPERATION_FAILED; } - tempstr = strndup(str + pmatch[1].rm_so, (size_t)len); + char *tempstr = strndup(str + pmatch[1].rm_so, (size_t)len); if (NULL == tempstr) { SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Memory allocation is failed"); @@ -1861,7 +1859,6 @@ static int __vc_cmd_tabsolute_check(const char *str, struct tm *td, int *exist) int min = -1; int sidx = -1; int eidx = -1; - char *tempstr = NULL; *exist = 0; ret = regexec(®[0], str, 5, pmatch, 0); @@ -1882,7 +1879,7 @@ static int __vc_cmd_tabsolute_check(const char *str, struct tm *td, int *exist) SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid string length"); return VC_ERROR_OPERATION_FAILED; } - tempstr = strndup(str + pmatch[1].rm_so, (size_t)len); + char *tempstr = strndup(str + pmatch[1].rm_so, (size_t)len); if (NULL == tempstr) { SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Memory allocation is failed"); @@ -1922,7 +1919,7 @@ static int __vc_cmd_tabsolute_check(const char *str, struct tm *td, int *exist) idx = 1; len = pmatch[idx].rm_eo - pmatch[idx].rm_so; if (0 < len) { - tempstr = strndup(str + pmatch[idx].rm_so, (size_t)len); + char *tempstr = strndup(str + pmatch[idx].rm_so, (size_t)len); if (NULL == tempstr) { SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Memory allocation is failed"); diff --git a/server/vcd_client_data.c b/server/vcd_client_data.c index de4c8cf..ab42c56 100644 --- a/server/vcd_client_data.c +++ b/server/vcd_client_data.c @@ -396,13 +396,10 @@ manager_tidl_info_s* vcd_client_manager_get_tidl_info() static void __vcd_client_release_each_commands(GSList** cmds) { - GSList *iter = NULL; - vc_cmd_s* temp_cmd; - if (0 < g_slist_length(*cmds)) { - iter = g_slist_nth(*cmds, 0); + GSList *iter = g_slist_nth(*cmds, 0); while (NULL != iter) { - temp_cmd = iter->data; + vc_cmd_s *temp_cmd = iter->data; if (NULL != temp_cmd) { if (NULL != temp_cmd->command) { diff --git a/server/vcd_server.c b/server/vcd_server.c index ebdfaf8..9945e0c 100644 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -342,12 +342,9 @@ static bool __vcd_launch_app(const char* result) if (0 != g_slist_length(app_list)) { /* release data */ - GSList *iter = NULL; - vc_deactivated_app_s* temp_app = NULL; - iter = g_slist_nth(app_list, 0); - + GSList *iter = g_slist_nth(app_list, 0); while (NULL != iter) { - temp_app = iter->data; + vc_deactivated_app_s *temp_app = iter->data; if (NULL != temp_app && NULL != temp_app->appid) { int ret = -1; @@ -402,15 +399,13 @@ static Eina_Bool __vcd_send_selected_result(void *data) SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to get pid list. No result"); } else { if (0 < g_slist_length(pid_list)) { - GSList* iter = NULL; - vc_cmd_s* temp_cmd = NULL; int ret = 0; int pre_pid = -1; int pre_type = -1; - iter = g_slist_nth(pid_list, 0); + GSList *iter = g_slist_nth(pid_list, 0); while (NULL != iter) { - temp_cmd = iter->data; + vc_cmd_s *temp_cmd = iter->data; if (NULL != temp_cmd && (pre_pid != temp_cmd->pid || pre_type == VC_COMMAND_TYPE_WIDGET || temp_cmd->type == VC_COMMAND_TYPE_WIDGET)) { /* Launch deactivated several apps that is matched with result */ -- 2.34.1