S390: Get rid of format warning in bug-vfprintf-nargs.c
diff mbox

Message ID m6ev3k$u30$1@ger.gmane.org
State New
Headers show

Commit Message

Stefan Liebler Dec. 12, 2014, 2:46 p.m. UTC
Hi,

on 31bit s390 i get the following warning/error:
gcc bug-vfprintf-nargs.c -c ...
bug-vfprintf-nargs.c: In function ‘do_test’:
bug-vfprintf-nargs.c:68:7: error: format ‘%d’ expects argument of type 
‘int’, but argument 3 has type ‘long unsigned int’ [-Werror=format=]
        sprintf (buf, "%%1$d %%%" PRIdPTR "$d", UINT32_MAX / sizeof (int));

This patch suppresses the format warning with the diagnostic control 
pragmas.
Thus the behaviour of this testcase isn´t changed.

Ok to commit?

Bye
Stefan

---
2014-12-12  Stefan Liebler  <stli@linux.vnet.ibm.com>

	* stdio-common/bug-vfprintf-nargs.c (do_test):
	Disable format warning with diagnostic control pragma.

Comments

Roland McGrath Dec. 12, 2014, 9:12 p.m. UTC | #1
I think you can just cast the value to intptr_t.

Patch
diff mbox

diff --git a/stdio-common/bug-vfprintf-nargs.c b/stdio-common/bug-vfprintf-nargs.c
index c7e7f0b..7406b7a 100644
--- a/stdio-common/bug-vfprintf-nargs.c
+++ b/stdio-common/bug-vfprintf-nargs.c
@@ -24,6 +24,7 @@ 
 #include <inttypes.h>
 #include <string.h>
 #include <signal.h>
+#include <libc-internal.h>
 
 static int
 format_failed (const char *fmt, const char *expected)
@@ -65,7 +66,13 @@  do_test (void)
      test this on 32-bit systems.  */
   if (sizeof (long int) == 4)
     {
+      /* On S390 31bit, gcc emits the warning:
+	 format ‘%d’ expects argument of type ‘int’,
+	 but argument 3 has type ‘long unsigned int’.  */
+      DIAG_PUSH_NEEDS_COMMENT;
+      DIAG_IGNORE_NEEDS_COMMENT (5, "-Wformat");
       sprintf (buf, "%%1$d %%%" PRIdPTR "$d", UINT32_MAX / sizeof (int));
+      DIAG_POP_NEEDS_COMMENT;
       if (format_failed (buf, "1 %$d") != 0)
         rc = 1;
     }