This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
commit 18bb3331f3c6c9a568af968777f93611b735cc6e Author: Xiang Xiao <[email protected]> AuthorDate: Sun Mar 6 18:20:50 2022 +0800 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 <[email protected]> --- 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 a20ab7e..fde1190 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 */
