Remove 'format-truncation' warning for GCC-9 26/221126/1 accepted/tizen/unified/20200106.141605 submit/tizen/20200103.083647
authorYunmi Ha <yunmi.ha@samsung.com>
Fri, 27 Dec 2019 08:32:31 +0000 (17:32 +0900)
committerYunmi Ha <yunmi.ha@samsung.com>
Fri, 27 Dec 2019 08:32:31 +0000 (17:32 +0900)
Change-Id: I561072c619f169309d66dde7a1946664b8d55935
Signed-off-by: Yunmi Ha <yunmi.ha@samsung.com>
src/storage.c

index 314f622..6778dff 100644 (file)
@@ -218,8 +218,12 @@ API int storage_get_directory(int storage_id, storage_directory_e type, char **p
                                *end = '\0';
                        snprintf(temp, PATH_MAX, "%s", temp2);
                        free(temp2);
-               } else
-                       snprintf(temp, PATH_MAX, "%s/%s", root, dir_path[type]);
+               } else {
+                       if ((ret = snprintf(temp, PATH_MAX, "%s/%s", root, dir_path[type])) > PATH_MAX - 1) {
+                               _E("Path is longer than buffer. Need %d size of buffer.", ret + 1);
+                               return STORAGE_ERROR_OUT_OF_MEMORY;
+                       }
+               }
 
                goto out;
        }
@@ -249,7 +253,10 @@ API int storage_get_directory(int storage_id, storage_directory_e type, char **p
        if (extendedint)
                return STORAGE_ERROR_INVALID_PARAMETER;
 
-       snprintf(temp, sizeof(temp), "%s/%s", root, dir_path[type]);
+       if ((ret = snprintf(temp, sizeof(temp), "%s/%s", root, dir_path[type])) > sizeof(temp) - 1) {
+               _E("Path is longer than buffer. Need %d size of buffer.", ret + 1);
+               return STORAGE_ERROR_OUT_OF_MEMORY;
+       }
 
 out:
        *path = strdup(temp);