Remove compile warning messages 68/222168/6
authorIlho Kim <ilho159.kim@samsung.com>
Fri, 10 Jan 2020 05:25:11 +0000 (14:25 +0900)
committerIlho Kim <ilho159.kim@samsung.com>
Fri, 10 Jan 2020 06:58:53 +0000 (15:58 +0900)
This patch for fixing build warning caused by toolchain version-up
(applying GCC-9)

Change-Id: I3ddb98c7f8c79a03adfe8bcce2b6b58fa603a248
Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
parser/src/pkgmgr_parser_db.c
parser/src/pkgmgr_parser_deprecated.c
src/pkgmgrinfo_appinfo.c
src/pkgmgrinfo_pkginfo.c
tool/pkg-db-recovery.c

index 5402229..7f1738d 100644 (file)
@@ -1364,8 +1364,12 @@ static gint __check_icon_resolution(const char *orig_icon_path,
                        strlen(orig_icon_path) - (strlen(icon_filename) - 1),
                        "%s", orig_icon_path);
        for (i = 0; i < 2; i++) {
-               snprintf(modified_iconpath, BUFSIZE - 1, "%s/%s%s",
+               ret = snprintf(modified_iconpath, BUFSIZE - 1, "%s/%s%s",
                                icon_path, dpi_path[i], icon_filename);
+               if (ret < 0 || ret > BUFSIZE -1) {
+                       _LOGE("snprintf fail");
+                       return -1;
+               }
                if (access(modified_iconpath, F_OK) != -1) {
                        /* if exists, return modified icon path */
                        *new_icon_path = strdup(modified_iconpath);
index d717409..16c2507 100644 (file)
@@ -1323,6 +1323,7 @@ static char *__get_parser_plugin(const char *type)
        char buffer[1024] = { 0 };
        char temp_path[1024] = { 0 };
        char *path = NULL;
+       int ret = -1;
 
        if (type == NULL) {
                _LOGE("invalid argument\n");
@@ -1357,7 +1358,11 @@ static char *__get_parser_plugin(const char *type)
                return NULL;
        }
 
-       snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
+       ret = snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
+       if (ret < 0 || ret > sizeof(temp_path) -1) {
+               _LOGE("snprintf fail");
+               return NULL;
+       }
 
        return strdup(temp_path);
 }
@@ -1649,7 +1654,12 @@ static int __run_metadata_parser_prestep(manifest_x *mfx, char *md_key, ACTION_T
                                continue;
                        /* get glist of metadata key and value combination */
                        memset(buffer, 0x00, 1024);
-                       snprintf(buffer, 1024, "%s/", md_key);
+                       ret = snprintf(buffer, 1024, "%s/", md_key);
+                       if (ret < 0 || ret > 1024) {
+                               _LOGD("snprintf fail\n");
+                               ret = -1;
+                               goto END;
+                       }
                        if ((md->key && md->value) && (strncmp(md->key, md_key, strlen(md_key)) == 0) && (strncmp(buffer, md->key, strlen(buffer)) == 0)) {
                                md_detail = (__metadata_t*) calloc(1, sizeof(__metadata_t));
                                if (md_detail == NULL) {
@@ -1876,7 +1886,12 @@ static int __run_category_parser_prestep(manifest_x *mfx, char *category_key, AC
                        category = (const char *)category_tmp->data;
                        /* get glist of category key and value combination */
                        memset(buffer, 0x00, 1024);
-                       snprintf(buffer, 1024, "%s/", category_key);
+                       ret = snprintf(buffer, 1024, "%s/", category_key);
+                       if (ret < 0 || ret > 1024) {
+                               _LOGD("snprintf fail\n");
+                               ret = -1;
+                               goto END;
+                       }
                        if ((category) && (strncmp(category, category_key, strlen(category_key)) == 0)) {
                                category_detail = (__category_t*) calloc(1, sizeof(__category_t));
                                if (category_detail == NULL) {
index 6089262..e88018f 100644 (file)
@@ -60,6 +60,7 @@ static int _get_filtered_query(pkgmgrinfo_filter_x *filter,
        const char *locale, uid_t uid, char **query, GList **bind_params)
 {
        int joined = 0;
+       int size;
        char *condition = NULL;
        char buf[MAX_QUERY_LEN] = { '\0' };
        char tmp_query[MAX_QUERY_LEN] = { '\0' };
@@ -110,11 +111,11 @@ static int _get_filtered_query(pkgmgrinfo_filter_x *filter,
        if (joined & E_PMINFO_APPINFO_JOIN_PRIVILEGE)
                strncat(tmp_query, join_privilege, sizeof(tmp_query) - strlen(tmp_query) - 1);
 
-       strncat(tmp_query, buf, sizeof(tmp_query) - strlen(tmp_query) - 1);
-
-       *query = strdup(tmp_query);
+       size = strlen(tmp_query) + strlen(buf) + 1;
+       *query = (char *)calloc(1, size);
        if (*query == NULL)
                return PMINFO_R_ERROR;
+       snprintf(*query, size, "%s%s", tmp_query, buf);
 
        return PMINFO_R_OK;
 }
@@ -3408,6 +3409,7 @@ API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
        char temp[PKG_STRING_LEN_MAX] = {'\0'};
        GSList *link = NULL;
        int prop = -1;
+       int ret;
        prop = _pminfo_appinfo_convert_to_prop_str(property);
        if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
                prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
@@ -3443,15 +3445,21 @@ API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
                        strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
                        _LOGI("Previous value is %s\n", prev);
                        filter->list = g_slist_delete_link(filter->list, link);
-                       snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s,%s", prev, value);
-                       strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
+                       ret = snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s,%s", prev, value);
+                       if (ret < 0 || ret > PKG_STRING_LEN_MAX - 1) {
+                               _LOGE("snprintf fail\n");
+                               free(node);
+                               free(val);
+                               return PMINFO_R_ERROR;
+                       }
+                       strncpy(val, temp, PKG_STRING_LEN_MAX);
                        _LOGI("New value is %s\n", val);
                        node->value = val;
                        filter->list = g_slist_append(filter->list, (gpointer)node);
                        memset(temp, '\0', PKG_STRING_LEN_MAX);
                } else {
                        snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s", value);
-                       strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
+                       strncpy(val, temp, PKG_STRING_LEN_MAX);
                        _LOGI("First value is %s\n", val);
                        node->value = val;
                        filter->list = g_slist_append(filter->list, (gpointer)node);
index dc3048a..4235b42 100644 (file)
@@ -368,6 +368,7 @@ static int _get_filtered_query(pkgmgrinfo_filter_x *filter,
                const char *locale, uid_t uid, char **query, GList **bind_params)
 {
        int joined = 0;
+       int size;
        char buf[MAX_QUERY_LEN] = { '\0' };
        char buf2[MAX_QUERY_LEN] = { '\0' };
        char *condition = NULL;
@@ -396,11 +397,12 @@ static int _get_filtered_query(pkgmgrinfo_filter_x *filter,
        }
        if (joined & E_PMINFO_PKGINFO_JOIN_PRIVILEGE_INFO)
                strncat(buf2, join_privilege_info, sizeof(buf2) - strlen(buf2) - 1);
-       strncat(buf2, buf, sizeof(buf2) - strlen(buf2) - 1);
 
-       *query = strdup(buf2);
+       size = strlen(buf2) + strlen(buf) + 1;
+       *query = (char *)calloc(1, size);
        if (*query == NULL)
                return PMINFO_R_ERROR;
+       snprintf(*query, size, "%s%s", buf2, buf);
 
        return PMINFO_R_OK;
 }
index 3aae1af..932fd21 100644 (file)
@@ -439,8 +439,13 @@ static void _get_user_list()
        dir = opendir(traverse_path);
 
        while ((ent = readdir(dir)) != NULL) {
-               snprintf(abs_dirname, PATH_MAX, "%s/%s", traverse_path,
+               ret = snprintf(abs_dirname, PATH_MAX, "%s/%s", traverse_path,
                         ent->d_name);
+               if (ret < 0 || ret > PATH_MAX) {
+                       LOGE("snprintf fail");
+                       closedir(dir);
+                       return;
+               }
 
                ret = stat(abs_dirname, &stats);
                if (ret != 0) {