Rearrange the scope of each temporary variables 06/291006/1 accepted/tizen/unified/20230407.140022
authorSuyeon Hwang <stom.hwang@samsung.com>
Thu, 6 Apr 2023 05:09:29 +0000 (14:09 +0900)
committerTizen AI <ai.tzn.sec@samsung.com>
Thu, 6 Apr 2023 09:06:24 +0000 (18:06 +0900)
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 <stom.hwang@samsung.com>
common/vc_cmd_db.c
common/vc_command.c
server/vcd_client_data.c
server/vcd_server.c

index 2ddbb479ec542d62b8a116b30ad4699cacb9e4f5..9a308489b5fea0aabef717123f8c6ca1d661e13c 100644 (file)
@@ -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);
index 1c63b22deeea0fd10effc94855a4c95ffda0fcee..e6b5767e71e6a849fa4328049d4e1e0ba9cb1764 100644 (file)
@@ -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(&reg[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(&reg[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");
index de4c8cf3429d68d1c1c75e22aaa5a91eb3919c33..ab42c561a3bc4f0fc7d4b3f24472c8637a1486c6 100644 (file)
@@ -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) {
index ebdfaf8d1180995ad4c183794c421b541fcb083e..9945e0ce481bea5fcb70118616acf073fada6c81 100644 (file)
@@ -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 */