Message ID | 20240626123746.2533951-1-stli@linux.ibm.com |
---|---|
State | New |
Headers | show |
Series | tests-mbwc: Silence gcc 14 -Werror=format-overflow= | expand |
On Jun 26 2024, Stefan Liebler wrote: > With gcc 14, I get this warning/werror when building the localedata tests: > tests-mbwc/tsp_common.c: In function ‘result.constprop.isra’: > tests-mbwc/tsp_common.c:55:43: error: ‘%s’ directive writing up to 92 bytes into a region of size between 0 and 114 [-Werror=format-overflow=] > 55 | sprintf (result_rec, "%s:%s:%d:%d:%d:%c:%s\n", func, loc, rec_no, seq_no, What's the point of result_rec, anyway? This could just print to fp directly.
On 26.06.24 15:19, Andreas Schwab wrote: > On Jun 26 2024, Stefan Liebler wrote: > >> With gcc 14, I get this warning/werror when building the localedata tests: >> tests-mbwc/tsp_common.c: In function ‘result.constprop.isra’: >> tests-mbwc/tsp_common.c:55:43: error: ‘%s’ directive writing up to 92 bytes into a region of size between 0 and 114 [-Werror=format-overflow=] >> 55 | sprintf (result_rec, "%s:%s:%d:%d:%d:%c:%s\n", func, loc, rec_no, seq_no, > > What's the point of result_rec, anyway? This could just print to fp > directly. > Sure, this is possible. I've just send V2 with this adjustment: [PATCH v2] tests-mbwc: Silence gcc 14 -Werror=format-overflow= https://sourceware.org/pipermail/libc-alpha/2024-June/157833.html
diff --git a/localedata/tests-mbwc/tsp_common.c b/localedata/tests-mbwc/tsp_common.c index cd88274c57..f09cdaf511 100644 --- a/localedata/tests-mbwc/tsp_common.c +++ b/localedata/tests-mbwc/tsp_common.c @@ -44,7 +44,8 @@ result (FILE * fp, char res, const char *func, const char *loc, int rec_no, int seq_no, int case_no, const char *msg) { if (fp == NULL - || strlen (func) + strlen (loc) + strlen (msg) + 32 > MAX_RESULT_REC) + || snprintf (result_rec, MAX_RESULT_REC, "%s:%s:%d:%d:%d:%c:%s\n", func, + loc, rec_no, seq_no, case_no, res, msg) >= MAX_RESULT_REC) { fprintf (stderr, "Warning: result(): can't write the result: %s:%s:%d:%d:%s\n", @@ -52,9 +53,6 @@ result (FILE * fp, char res, const char *func, const char *loc, int rec_no, return 0; } - sprintf (result_rec, "%s:%s:%d:%d:%d:%c:%s\n", func, loc, rec_no, seq_no, - case_no, res, msg); - if (fputs (result_rec, fp) == EOF) { return 0;