From: Jeff Law <law@redhat.com>
To: Martin Sebor <msebor@gmail.com>,
Gcc Patch List <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] correct handling of non-constant width and precision (pr 78521)
Date: Mon, 28 Nov 2016 20:26:00 -0000 [thread overview]
Message-ID: <1c540661-5d0f-5c0d-b97b-3378252aeaee@redhat.com> (raw)
In-Reply-To: <9b412cbb-1cb0-6341-5b85-78f235f7ae6f@gmail.com>
On 11/27/2016 08:34 PM, Martin Sebor wrote:
> PR 78521 notes that the gimple-ssa-sprintf pass doesn't do the right
> thing (i.e., the -Wformat-length and -fprintf-return-value options
> behave incorrectly) when a conversion specification includes a width
> or precision with a non-constant value. The code treats such cases
> as if they were not provided which is incorrect and results in
> the wrong bytes counts in warning messages and in the wrong ranges
> being generated for such calls (or in the case sprintf(0, 0, ...)
> for some such calls being eliminated).
>
> The attached patch corrects the handling of these cases, plus a couple
> of other edge cases in the same area: it adjusts the parser to accept
> precision in the form of just a period with no asterisk or decimal
> digits after it (this sets the precision to zero), and corrects the
> handling of zero precision and zero argument in integer directives
> to produce no bytes on output.
>
> Finally, the patch also tightens up the constraint on the upper bound
> of bounded functions like snprintf to be INT_MAX. The functions cannot
> produce output in excess of INT_MAX + 1 bytes and some implementations
> (e.g., Solaris) fail with EINVAL when the bound is INT_MAX or more.
> This is the subject of PR 78520.
>
> Thanks
> Martin
>
> gcc-78521.diff
>
>
> PR middle-end/78521 - [7 Regression] incorrect byte count in -Wformat-length warning with non-constant width or precision
> PR middle-end/78520 - missing warning for snprintf with size greater than INT_MAX
> gcc/ChangeLog:
>
> PR middle-end/78521
> PR middle-end/78520
> * gimple-ssa-sprintf.c (target_max_value): Remove.
> (target_int_max, target_size_max): Use TYPE_MAX_VALUE.
> (get_width_and_precision): New function.
> (format_integer, format_floating, get_string_length, format_string):
> Correct handling of width and precision with unknown value.
> (format_directive): Add warning.
> (pass_sprintf_length::compute_format_length): Allow for precision
> to consist of a sole period with no asterisk or digits after it.
>
> gcc/testsuite/ChangeLog:
>
> PR middle-end/78521
> PR middle-end/78520
> * gcc.dg/tree-ssa/builtin-sprintf-5.c: Add test cases.
> * gcc.dg/tree-ssa/builtin-sprintf-6.c: New test.
> * gcc.dg/tree-ssa/builtin-sprintf-warn-1.c: Add test cases.
> * gcc.dg/tree-ssa/builtin-sprintf-warn-3.c: Add test cases.
Fairly dense reading. Probably inherent due to the problem space.
OK for the trunk.
Thanks,
jeff
next prev parent reply other threads:[~2016-11-28 20:26 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-28 3:34 Martin Sebor
2016-11-28 20:26 ` Jeff Law [this message]
2016-11-29 0:42 ` Joseph Myers
2016-11-29 16:57 ` Martin Sebor
2016-11-29 20:14 ` Martin Sebor
2016-12-02 8:31 ` Rainer Orth
2016-12-02 15:52 ` Martin Sebor
2016-12-05 15:50 ` Martin Sebor
2016-12-05 15:54 ` Jakub Jelinek
2016-12-05 18:25 ` Jeff Law
2016-12-05 18:30 ` Marek Polacek
2016-12-05 18:37 ` Jeff Law
2016-12-05 18:39 ` Jakub Jelinek
2016-12-05 18:36 ` Jakub Jelinek
2016-12-05 18:53 ` Martin Sebor
2016-12-06 23:30 ` Jeff Law
2016-11-29 1:35 David Edelsohn
2016-11-29 2:59 ` Martin Sebor
2016-11-29 8:05 ` Christophe Lyon
2016-11-29 21:58 ` Martin Sebor
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1c540661-5d0f-5c0d-b97b-3378252aeaee@redhat.com \
--to=law@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=msebor@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).