public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Alan Hayward <Alan.Hayward@arm.com>
To: Tom Tromey <tom@tromey.com>
Cc: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>,
	nd <nd@arm.com>
Subject: Re: [RFA 2/3] Allow - in %p for printf
Date: Fri, 16 Feb 2018 11:31:00 -0000	[thread overview]
Message-ID: <6148D406-9234-4C7E-958F-2B7713C6B35B@arm.com> (raw)
In-Reply-To: <20180215205001.337-3-tom@tromey.com>



> On 15 Feb 2018, at 20:50, Tom Tromey <tom@tromey.com> wrote:
> 
> PR cli/19918 points out that a printf format like "%-5p" will cause a
> gdb crash.  The bug is problem is that printf_pointer doesn't take the
> "-" flag into account.
> 
> gdb/ChangeLog
> 2018-02-14  Tom Tromey  <tom@tromey.com>
> 
> 	PR cli/19918:
> 	* printcmd.c (printf_pointer): Allow "-" in format.
> 
> gdb/testsuite/ChangeLog
> 2018-02-14  Tom Tromey  <tom@tromey.com>
> 
> 	PR cli/19918:
> 	* gdb.base/printcmds.exp (test_printf): Add printf test using '-'
> 	flag.
> ---
> gdb/ChangeLog                        | 5 +++++
> gdb/printcmd.c                       | 5 +++--
> gdb/testsuite/ChangeLog              | 6 ++++++
> gdb/testsuite/gdb.base/printcmds.exp | 4 ++++
> 4 files changed, 18 insertions(+), 2 deletions(-)
> 
> diff --git a/gdb/printcmd.c b/gdb/printcmd.c
> index 13b967f0a2..d2d13895f6 100644
> --- a/gdb/printcmd.c
> +++ b/gdb/printcmd.c
> @@ -2399,8 +2399,9 @@ printf_pointer (struct ui_file *stream, const char *format,
>   if (val != 0)
>     *fmt_p++ = '#';
> 
> -  /* Copy any width.  */
> -  while (*p >= '0' && *p < '9')
> +  /* Copy any width or flags.  Only the "-" flag is needed -- see the
> +     format_pieces constructor.  */

I found this comment a little confusing. How about something like:
Copy and width or flags. “-“ is the only valid flag for pointers — see the format_pieces constructor.

Otherwise looks good to me.

> +  while (*p == '-' || (*p >= '0' && *p < '9'))
>     *fmt_p++ = *p++;
> 
>   gdb_assert (*p == 'p' && *(p + 1) == '\0');
> diff --git a/gdb/testsuite/gdb.base/printcmds.exp b/gdb/testsuite/gdb.base/printcmds.exp
> index 9402d97ef3..56cedb908f 100644
> --- a/gdb/testsuite/gdb.base/printcmds.exp
> +++ b/gdb/testsuite/gdb.base/printcmds.exp
> @@ -776,6 +776,10 @@ proc test_printf {} {
> 	"" \
> 	"create hibob command"
>     gdb_test "hibob" "hi bob zzz.*y" "run hibob command"
> +
> +    # PR cli/19918.
> +    gdb_test "printf \"%-16dq\\n\", 0" "0               q"
> +    gdb_test "printf \"%-16pq\\n\", 0" "\\(nil\\)           q"
> }
> 
> #Test printing DFP values with printf
> -- 
> 2.13.6
> 


  reply	other threads:[~2018-02-16 11:31 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-15 20:50 [RFA 0/3] a few minor printf fixes Tom Tromey
2018-02-15 20:50 ` [RFA 1/3] Add usage to printf command Tom Tromey
2018-02-16 11:35   ` Alan Hayward
2018-02-16 21:58     ` Tom Tromey
2018-02-16 23:09       ` Simon Marchi
2018-02-19  9:16         ` Alan Hayward
2018-02-15 20:50 ` [RFA 3/3] Special case NULL when using printf's %s format Tom Tromey
2018-02-16 12:08   ` Pedro Alves
2018-02-16 12:25     ` Pedro Alves
2018-02-16 21:58       ` Tom Tromey
2018-02-15 20:50 ` [RFA 2/3] Allow - in %p for printf Tom Tromey
2018-02-16 11:31   ` Alan Hayward [this message]
2018-02-27  3:50     ` Tom Tromey
2018-03-14 15:44 ` [RFA 0/3] a few minor printf fixes Tom Tromey

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=6148D406-9234-4C7E-958F-2B7713C6B35B@arm.com \
    --to=alan.hayward@arm.com \
    --cc=gdb-patches@sourceware.org \
    --cc=nd@arm.com \
    --cc=tom@tromey.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).