From 30b2d073622148d52a68486855cff7c7440f0b85 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 20 Nov 2018 20:34:29 +0100 Subject: [PATCH] Fix compile error with GCC 8 in makefsdata MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit lwip/lwip/src/apps/http/makefsdata/makefsdata.c:929:56: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=] snprintf(qualifiedName, sizeof(qualifiedName), "%s/%s", curSubdir, filename); /home/dziegel/lwip/lwip/src/apps/http/makefsdata/makefsdata.c:929:3: note: ‘snprintf’ output 2 or more bytes (assuming 257) into a destination of size 256 snprintf(qualifiedName, sizeof(qualifiedName), "%s/%s", curSubdir, filename); Reduce subdir string length by 3 bytes to make the warning go away. The whole file path including directory AND filename is limited to MAX_PATH_LEN - so it is reasonable to reserve 3 bytes less for directory - the filename won't fit anyway in the remaining 3 bytes. --- src/apps/http/makefsdata/makefsdata.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/apps/http/makefsdata/makefsdata.c b/src/apps/http/makefsdata/makefsdata.c index aa888748..d78dac92 100644 --- a/src/apps/http/makefsdata/makefsdata.c +++ b/src/apps/http/makefsdata/makefsdata.c @@ -132,7 +132,7 @@ static int file_can_be_compressed(const char* filename); /* 5 bytes per char + 3 bytes per line */ static char file_buffer_c[COPY_BUFSIZE * 5 + ((COPY_BUFSIZE / HEX_BYTES_PER_LINE) * 3)]; -char curSubdir[MAX_PATH_LEN]; +char curSubdir[MAX_PATH_LEN-3]; char lastFileVar[MAX_PATH_LEN]; char hdr_buf[4096]; @@ -926,9 +926,9 @@ int process_file(FILE *data_file, FILE *struct_file, const char *filename) int flags_printed; /* create qualified name (@todo: prepend slash or not?) */ - sprintf(qualifiedName, "%s/%s", curSubdir, filename); + snprintf(qualifiedName, sizeof(qualifiedName), "%s/%s", curSubdir, filename); /* create C variable name */ - strcpy(varname, qualifiedName); + strncpy(varname, qualifiedName, sizeof(varname)); /* convert slashes & dots to underscores */ fix_filename_for_c(varname, MAX_PATH_LEN); register_filename(varname);