diff mbox series

[v2] tests-mbwc: Silence gcc 14 -Werror=format-overflow=

Message ID 20240627114237.20232-1-stli@linux.ibm.com
State New
Headers show
Series [v2] tests-mbwc: Silence gcc 14 -Werror=format-overflow= | expand

Commit Message

Stefan Liebler June 27, 2024, 11:42 a.m. UTC
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,
      |                                           ^~
In file included from ../include/bits/stdio2.h:1,
                 from ../libio/stdio.h:980,
                 from ../include/stdio.h:14,
                 from tests-mbwc/tsp_common.c:10:
In function ‘sprintf’,
    inlined from ‘result.constprop.isra’ at tests-mbwc/tsp_common.c:55:3:
../libio/bits/stdio2.h:30:10: note: ‘__builtin___sprintf_chk’ output between 20 and 234 bytes into a destination of size 132
   30 |   return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   31 |                                   __glibc_objsize (__s), __fmt,
      |                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   32 |                                   __va_arg_pack ());
      |                                   ~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

This patch now gets rid of using sprintf and the result_rec buffer and just
prints to fp directly.
---
 localedata/tests-mbwc/tsp_common.c | 24 +++++-------------------
 1 file changed, 5 insertions(+), 19 deletions(-)

Comments

Andreas Schwab June 27, 2024, 12:40 p.m. UTC | #1
On Jun 27 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,
>       |                                           ^~
> In file included from ../include/bits/stdio2.h:1,
>                  from ../libio/stdio.h:980,
>                  from ../include/stdio.h:14,
>                  from tests-mbwc/tsp_common.c:10:
> In function ‘sprintf’,
>     inlined from ‘result.constprop.isra’ at tests-mbwc/tsp_common.c:55:3:
> ../libio/bits/stdio2.h:30:10: note: ‘__builtin___sprintf_chk’ output between 20 and 234 bytes into a destination of size 132
>    30 |   return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
>       |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>    31 |                                   __glibc_objsize (__s), __fmt,
>       |                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>    32 |                                   __va_arg_pack ());
>       |                                   ~~~~~~~~~~~~~~~~~
> cc1: all warnings being treated as errors
>
> This patch now gets rid of using sprintf and the result_rec buffer and just
> prints to fp directly.

Ok.
Stefan Liebler June 27, 2024, 2:52 p.m. UTC | #2
On 27.06.24 14:40, Andreas Schwab wrote:
> On Jun 27 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,
>>       |                                           ^~
>> In file included from ../include/bits/stdio2.h:1,
>>                  from ../libio/stdio.h:980,
>>                  from ../include/stdio.h:14,
>>                  from tests-mbwc/tsp_common.c:10:
>> In function ‘sprintf’,
>>     inlined from ‘result.constprop.isra’ at tests-mbwc/tsp_common.c:55:3:
>> ../libio/bits/stdio2.h:30:10: note: ‘__builtin___sprintf_chk’ output between 20 and 234 bytes into a destination of size 132
>>    30 |   return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
>>       |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>    31 |                                   __glibc_objsize (__s), __fmt,
>>       |                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>    32 |                                   __va_arg_pack ());
>>       |                                   ~~~~~~~~~~~~~~~~~
>> cc1: all warnings being treated as errors
>>
>> This patch now gets rid of using sprintf and the result_rec buffer and just
>> prints to fp directly.
> 
> Ok.
> 
Thanks. Committed the patch.
diff mbox series

Patch

diff --git a/localedata/tests-mbwc/tsp_common.c b/localedata/tests-mbwc/tsp_common.c
index cd88274c57..0c638efbb0 100644
--- a/localedata/tests-mbwc/tsp_common.c
+++ b/localedata/tests-mbwc/tsp_common.c
@@ -35,30 +35,16 @@  main (int argc, char *argv[])
   return (ret != 0);
 }
 
-#define	 MAX_RESULT_REC	 132
-char result_rec[MAX_RESULT_REC];
-
-
 int
 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)
-    {
-      fprintf (stderr,
-	       "Warning: result(): can't write the result: %s:%s:%d:%d:%s\n",
-	       func, loc, rec_no, case_no, msg);
-      return 0;
-    }
+  if (fp == NULL)
+    fp = stderr;
 
-  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;
-    }
+  if (fprintf (fp, "%s:%s:%d:%d:%d:%c:%s\n", func, loc, rec_no, seq_no,
+	       case_no, res, msg) == EOF)
+    return 0;
 
   return 1;
 }