From a57c5f01be052d85a4f3f99223239a69abecd6bf Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Fri, 27 Dec 2019 17:32:31 +0900 Subject: [PATCH] Remove 'format-truncation' warning for GCC-9 Change-Id: I561072c619f169309d66dde7a1946664b8d55935 Signed-off-by: Yunmi Ha --- src/storage.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/storage.c b/src/storage.c index 314f622..6778dff 100644 --- a/src/storage.c +++ b/src/storage.c @@ -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); -- 2.7.4