From 18bb3331f3c6c9a568af968777f93611b735cc6e Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Sun, 6 Mar 2022 18:20:50 +0800 Subject: [PATCH] netutils/webserver: Fix the compiler warning httpd_dirlist.c: In function 'httpd_dirlist': Error: httpd_dirlist.c:199:40: error: '%s' directive output may be truncated writing up to 255 bytes into a region of size 128 [-Werror=format-truncation=] 199 | snprintf(path, CONFIG_NAME_MAX, "%s/%s", | ^~ httpd_dirlist.c:199:7: note: 'snprintf' output between 2 and 385 bytes into a destination of size 128 199 | snprintf(path, CONFIG_NAME_MAX, "%s/%s", | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 200 | file->path, dent->d_name); | ~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Xiang Xiao --- netutils/webserver/httpd_dirlist.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/netutils/webserver/httpd_dirlist.c b/netutils/webserver/httpd_dirlist.c index a20ab7e90..fde1190b7 100644 --- a/netutils/webserver/httpd_dirlist.c +++ b/netutils/webserver/httpd_dirlist.c @@ -193,11 +193,8 @@ ssize_t httpd_dirlist(int outfd, FAR struct httpd_fs_file *file) break; } - path = malloc(CONFIG_NAME_MAX); - ASSERT(path); - - snprintf(path, CONFIG_NAME_MAX, "%s/%s", - file->path, dent->d_name); + ret = asprintf(&path, "%s/%s", file->path, dent->d_name); + ASSERT(ret > 0 && path); /* call stat() to obtain modified time and size */