Remove compile warning messages 70/221370/3
authorIlho Kim <ilho159.kim@samsung.com>
Thu, 2 Jan 2020 02:11:33 +0000 (11:11 +0900)
committerIlho Kim <ilho159.kim@samsung.com>
Tue, 7 Jan 2020 03:47:33 +0000 (12:47 +0900)
Change-Id: Ie96628caee7db57a3c9d17c3dd6d6d9ffe596022
Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
src/delta.c
src/pkg_cmd.c
src/pkg_rsc_slice.c

index c105d4f..ac572fe 100644 (file)
@@ -226,17 +226,21 @@ void __create_diff_file(char *old_tpk_path, char *new_tpk_path)
                                        ret = __compare_files(rel_path_old_tpk_file,
                                                        rel_path_new_tpk_file);
                                        if (ret == 1) {
-                                               snprintf(message, MAX_MESSAGE_LEN,
+                                               ret = snprintf(message, MAX_MESSAGE_LEN,
                                                                "Files %s and %s differ",
                                                                rel_path_old_tpk_file,
                                                                rel_path_new_tpk_file);
+                                               if (ret < 0 || ret > MAX_MESSAGE_LEN)
+                                                       printf("snprintf fail\n");
                                                __print_to_file(message);
                                        } else {
-                                                snprintf(message, MAX_MESSAGE_LEN,
-                                                                 "Files %s and %s are the same",
-                                                                 rel_path_old_tpk_file,
-                                                                 rel_path_new_tpk_file);
-                                                __print_to_file(message);
+                                               ret = snprintf(message, MAX_MESSAGE_LEN,
+                                                               "Files %s and %s are the same",
+                                                               rel_path_old_tpk_file,
+                                                               rel_path_new_tpk_file);
+                                               if (ret < 0 || ret > MAX_MESSAGE_LEN)
+                                                       printf("snprintf fail\n");
+                                               __print_to_file(message);
                                        }
                                }
                                list_dir_new_tpk = g_list_delete_link(list_dir_new_tpk,
index 51ead2d..99ed770 100644 (file)
@@ -285,21 +285,27 @@ static int __app_return_cb(uid_t target_uid, int req_id, const char *pkg_type,
 
 static int __convert_to_absolute_path(pm_tool_args *data)
 {
-       char abs[PKG_NAME_STRING_LEN_MAX] = {'\0'};
-       char temp[PKG_NAME_STRING_LEN_MAX] = {'\0'};
+       char abs[PATH_MAX] = {'\0'};
+       char temp[PATH_MAX] = {'\0'};
        char *ptr = NULL;
+       int ret;
        if (data->pkg_path[0] == '\0') {
                printf("path is NULL\n");
                return -1;
        }
-       strncpy(temp, data->pkg_path, PKG_NAME_STRING_LEN_MAX - 1);
+       strncpy(temp, data->pkg_path, sizeof(temp));
        if (strchr(data->pkg_path, '/') == NULL) {
                if (getcwd(abs, PKG_NAME_STRING_LEN_MAX - 1) == NULL) {
                        printf("getcwd() failed\n");
                        return -1;
                }
                memset(data->pkg_path, '\0', PKG_NAME_STRING_LEN_MAX);
-               snprintf(data->pkg_path, PKG_NAME_STRING_LEN_MAX - 1, "%s/%s", abs, temp);
+               ret = snprintf(data->pkg_path, PKG_NAME_STRING_LEN_MAX - 1,
+                               "%s/%s", abs, temp);
+               if (ret < 0 || ret > PKG_NAME_STRING_LEN_MAX - 1) {
+                       printf("snprintf fail\n");
+                       return -1;
+               }
                return 0;
        }
        if (strncmp(data->pkg_path, "./", 2) == 0) {
@@ -310,7 +316,12 @@ static int __convert_to_absolute_path(pm_tool_args *data)
                }
                ptr = ptr + 2;
                memset(data->pkg_path, '\0', PKG_NAME_STRING_LEN_MAX);
-               snprintf(data->pkg_path, PKG_NAME_STRING_LEN_MAX - 1, "%s/%s", abs, ptr);
+               ret = snprintf(data->pkg_path, PKG_NAME_STRING_LEN_MAX - 1,
+                               "%s/%s", abs, ptr);
+               if (ret < 0 || ret > PKG_NAME_STRING_LEN_MAX - 1) {
+                       printf("snprintf fail\n");
+                       return -1;
+               }
                return 0;
        }
        return 0;
@@ -321,18 +332,23 @@ static int __convert_to_absolute_tep_path(pm_tool_args *data)
        char abs[PATH_MAX] = {'\0'};
        char temp[PATH_MAX] = {'\0'};
        char *ptr = NULL;
+       int ret;
        if (data->tep_path[0] == '\0') {
                printf("path is NULL\n");
                return -1;
        }
-       strncpy(temp, data->tep_path, PATH_MAX - 1);
+       strncpy(temp, data->tep_path, sizeof(temp));
        if (strchr(data->tep_path, '/') == NULL) {
                if (getcwd(abs, PATH_MAX - 1) == NULL || abs[0] == '\0') {
                        printf("getcwd() failed\n");
                        return -1;
                }
                memset(data->tep_path, '\0', PATH_MAX);
-               snprintf(data->tep_path, PATH_MAX - 1, "%s/%s", abs, temp);
+               ret = snprintf(data->tep_path, PATH_MAX - 1, "%s/%s", abs, temp);
+               if (ret < 0 || ret > PATH_MAX - 1) {
+                       printf("snprintf fail\n");
+                       return -1;
+               }
                return 0;
        }
        if (strncmp(data->tep_path, "./", 2) == 0) {
@@ -343,7 +359,11 @@ static int __convert_to_absolute_tep_path(pm_tool_args *data)
                }
                ptr = ptr + 2;
                memset(data->tep_path, '\0', PATH_MAX);
-               snprintf(data->tep_path, PATH_MAX - 1, "%s/%s", abs, ptr);
+               ret = snprintf(data->tep_path, PATH_MAX - 1, "%s/%s", abs, ptr);
+               if (ret < 0 || ret > PATH_MAX - 1) {
+                       printf("snprintf fail\n");
+                       return -1;
+               }
                return 0;
        }
        return 0;
index 520981b..93078e9 100644 (file)
@@ -70,7 +70,11 @@ static int __convert_to_abs_path(rsc_tool_args *data)
                return -1;
        }
 
-       snprintf(tmp, sizeof(tmp), "%s", data->res_path);
+       ret = snprintf(tmp, sizeof(tmp), "%s", data->res_path);
+       if (ret < 0 || ret > sizeof(tmp)) {
+               printf("snprintf fail\n");
+               return -1;
+       }
 
        buf = getcwd(cwd, BUF_SIZE - 1);
        if (buf == NULL) {
@@ -91,7 +95,7 @@ static int __convert_to_abs_path(rsc_tool_args *data)
        }
 
        memset(data->res_path, '\0', BUF_SIZE);
-       snprintf(data->res_path, BUF_SIZE - 1, "%s/", abs);
+       snprintf(data->res_path, sizeof(data->res_path), "%s/", abs);
        ret = chdir(cwd);
        if (ret < 0) {
                printf("failed to change dir[%s]\n", tmp);
@@ -140,7 +144,11 @@ static void __del_file(GHashTable *valid_file_list, char *path)
                if (items[i]->d_name[0] == '.')
                        continue;
 
-               snprintf(abs_path, 1024 - 1, "%s/%s", cwd, items[i]->d_name);
+               ret = snprintf(abs_path, 1024 - 1, "%s/%s", cwd, items[i]->d_name);
+               if (ret < 0 || ret > 1024 -1 ) {
+                       printf("snprintf fail\n");
+                       return;
+               }
                if (g_lstat(abs_path, &fstat) != 0) {
                        printf("failed to get info[%s]\n", abs_path);
                        return;