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 <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2022-03-06 18:20:50 +08:00 committed by Xiang Xiao
parent 65a02ba9f9
commit 18bb3331f3

View File

@ -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 */