Fix compile error with GCC 8 in makefsdata

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.

Ref IDF-4797
Picked from lwip-tcpip/lwip@30b2d073
This commit is contained in:
Dirk Ziegelmeier
2022-03-19 19:17:47 +01:00
committed by David Cermak
parent 6ca936f6b5
commit dd27077ab7
+3 -3
View File
@@ -128,7 +128,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];
@@ -920,9 +920,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);