* [PATCH] Fix warning from latest GCC in tst-printf.c
@ 2016-10-20 22:43 Steve Ellcey
2016-11-01 17:21 ` Steve Ellcey
0 siblings, 1 reply; 5+ messages in thread
From: Steve Ellcey @ 2016-10-20 22:43 UTC (permalink / raw)
To: libc-alpha
GCC 7.0 (prerelease) adds a a new warning, -Wformat-length, if it
thinks an snprintf call may go beyond the end of the buffer length
being written to.  This warning is an approximation since GCC may not
know how many characters a '%d' format will expand to, but it makes a
worse case guess and warns if that would take the print beyond the
buffer length.
Here is a fix for one GLIBC test that fails to compile due to this
warning. Â I think we want to ignore the warning in this case and not
increase the buffer size because I believe the test is intentionally
trying to go beyond the buffer limit.
The warnings are coming from the snprintf statements at line 225 and
228 of the original stdio-common/tst-printf.c and I could do a push and
pop of the warning down at those lines but I thought it made more sense
to put it up with the other DIAG_IGNORE.
OK to checkin?
Steve Ellcey
sellcey@caviumnetworks.com
2016-10-20  Steve Ellcey  <sellcey@caviumnetworks.com>
* stdio-common/tst-printf.c: Ignore -Wformat-length warning.
diff --git a/stdio-common/tst-printf.c b/stdio-common/tst-printf.c
index 2896b18..1ae1eea 100644
--- a/stdio-common/tst-printf.c
+++ b/stdio-common/tst-printf.c
@@ -32,6 +32,9 @@
    The compiler warnings are not useful here.  */
 DIAG_IGNORE_NEEDS_COMMENT (4.9, "-Wformat");
Â
+/* Compiler warnings about format lengths should also be ignored.  */
+DIAG_IGNORE_NEEDS_COMMENT (7.0, "-Wformat-length");
+
 static void rfg1 (void);
 static void rfg2 (void);
 static void rfg3 (void);
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Fix warning from latest GCC in tst-printf.c
2016-10-20 22:43 [PATCH] Fix warning from latest GCC in tst-printf.c Steve Ellcey
@ 2016-11-01 17:21 ` Steve Ellcey
2016-11-01 17:37 ` Joseph Myers
0 siblings, 1 reply; 5+ messages in thread
From: Steve Ellcey @ 2016-11-01 17:21 UTC (permalink / raw)
To: libc-alpha
Ping.  One of the snprintf statements in this test is using a %.999999u
format so it is obvious that the test wants to test formats that would
go beyond the limit of the snprintf buffer and so we should ignore the
warnings in this test.
Steve Ellcey
sellcey@caviumnetworks.com
On Thu, 2016-10-20 at 15:43 -0700, Steve Ellcey wrote:
> GCC 7.0 (prerelease) adds a a new warning, -Wformat-length, if it
> thinks an snprintf call may go beyond the end of the buffer length
> being written to.  This warning is an approximation since GCC may not
> know how many characters a '%d' format will expand to, but it makes a
> worse case guess and warns if that would take the print beyond the
> buffer length.
>
> Here is a fix for one GLIBC test that fails to compile due to this
> warning. Â I think we want to ignore the warning in this case and not
> increase the buffer size because I believe the test is intentionally
> trying to go beyond the buffer limit.
>
> The warnings are coming from the snprintf statements at line 225 and
> 228 of the original stdio-common/tst-printf.c and I could do a push
> and
> pop of the warning down at those lines but I thought it made more
> sense
> to put it up with the other DIAG_IGNORE.
>
> OK to checkin?
>
> Steve Ellcey
> sellcey@caviumnetworks.com
>
>
> 2016-10-20  Steve Ellcey  <sellcey@caviumnetworks.com>
>
> * stdio-common/tst-printf.c: Ignore -Wformat-length warning.
>
>
> diff --git a/stdio-common/tst-printf.c b/stdio-common/tst-printf.c
> index 2896b18..1ae1eea 100644
> --- a/stdio-common/tst-printf.c
> +++ b/stdio-common/tst-printf.c
> @@ -32,6 +32,9 @@
>     The compiler warnings are not useful here.  */
> Â DIAG_IGNORE_NEEDS_COMMENT (4.9, "-Wformat");
> Â
> +/* Compiler warnings about format lengths should also be
> ignored.  */
> +DIAG_IGNORE_NEEDS_COMMENT (7.0, "-Wformat-length");
> +
> Â static void rfg1 (void);
> Â static void rfg2 (void);
> Â static void rfg3 (void);
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Fix warning from latest GCC in tst-printf.c
2016-11-01 17:21 ` Steve Ellcey
@ 2016-11-01 17:37 ` Joseph Myers
2016-11-01 22:29 ` Steve Ellcey
0 siblings, 1 reply; 5+ messages in thread
From: Joseph Myers @ 2016-11-01 17:37 UTC (permalink / raw)
To: Steve Ellcey; +Cc: libc-alpha
[-- Attachment #1: Type: text/plain, Size: 492 bytes --]
On Tue, 1 Nov 2016, Steve Ellcey wrote:
> Ping.  One of the snprintf statements in this test is using a %.999999u
> format so it is obvious that the test wants to test formats that would
> go beyond the limit of the snprintf buffer and so we should ignore the
> warnings in this test.
OK provided you've tested that this change works with older GCC that lack
the new option (otherwise it would need to be conditional on the GCC
version).
--
Joseph S. Myers
joseph@codesourcery.com
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Fix warning from latest GCC in tst-printf.c
2016-11-01 17:37 ` Joseph Myers
@ 2016-11-01 22:29 ` Steve Ellcey
2016-11-01 22:54 ` Joseph Myers
0 siblings, 1 reply; 5+ messages in thread
From: Steve Ellcey @ 2016-11-01 22:29 UTC (permalink / raw)
To: Joseph Myers; +Cc: libc-alpha
On Tue, 2016-11-01 at 17:37 +0000, Joseph Myers wrote:
> On Tue, 1 Nov 2016, Steve Ellcey wrote:
>
> >
> > Ping.  One of the snprintf statements in this test is using a %.999999u
> > format so it is obvious that the test wants to test formats that would
> > go beyond the limit of the snprintf buffer and so we should ignore the
> > warnings in this test.
> OK provided you've tested that this change works with older GCC that lackÂ
> the new option (otherwise it would need to be conditional on the GCCÂ
> version).
I did forget to check it with an older GCC and it does fail with GCC
5.4. Â Here is a new version with a conditional. Â Tested with GCC 5.4
and GCC 7.0 (prerelease).
Ok to checkin?
Steve Ellcey
sellcey@caviumnetworks.com
2016-11-01  Steve Ellcey  <sellcey@caviumnetworks.com>
* stdio-common/tst-printf.c: Ignore -Wformat-length warning.
diff --git a/stdio-common/tst-printf.c b/stdio-common/tst-printf.c
index 2896b18..ffe7ac7 100644
--- a/stdio-common/tst-printf.c
+++ b/stdio-common/tst-printf.c
@@ -32,6 +32,11 @@
    The compiler warnings are not useful here.  */
 DIAG_IGNORE_NEEDS_COMMENT (4.9, "-Wformat");
Â
+#if __GNUC_PREREQ (7, 0)
+/* Compiler warnings about format lengths should also be ignored.  */
+DIAG_IGNORE_NEEDS_COMMENT (7.0, "-Wformat-length");
+#endif
+
 static void rfg1 (void);
 static void rfg2 (void);
 static void rfg3 (void);
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Fix warning from latest GCC in tst-printf.c
2016-11-01 22:29 ` Steve Ellcey
@ 2016-11-01 22:54 ` Joseph Myers
0 siblings, 0 replies; 5+ messages in thread
From: Joseph Myers @ 2016-11-01 22:54 UTC (permalink / raw)
To: Steve Ellcey; +Cc: libc-alpha
[-- Attachment #1: Type: text/plain, Size: 843 bytes --]
On Tue, 1 Nov 2016, Steve Ellcey wrote:
> On Tue, 2016-11-01 at 17:37 +0000, Joseph Myers wrote:
> > On Tue, 1 Nov 2016, Steve Ellcey wrote:
> >
> > >
> > > Ping.  One of the snprintf statements in this test is using a %.999999u
> > > format so it is obvious that the test wants to test formats that would
> > > go beyond the limit of the snprintf buffer and so we should ignore the
> > > warnings in this test.
> > OK provided you've tested that this change works with older GCC that lackÂ
> > the new option (otherwise it would need to be conditional on the GCCÂ
> > version).
>
> I did forget to check it with an older GCC and it does fail with GCC
> 5.4. Â Here is a new version with a conditional. Â Tested with GCC 5.4
> and GCC 7.0 (prerelease).
>
> Ok to checkin?
OK.
--
Joseph S. Myers
joseph@codesourcery.com
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-11-01 22:54 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-20 22:43 [PATCH] Fix warning from latest GCC in tst-printf.c Steve Ellcey
2016-11-01 17:21 ` Steve Ellcey
2016-11-01 17:37 ` Joseph Myers
2016-11-01 22:29 ` Steve Ellcey
2016-11-01 22:54 ` Joseph Myers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).