Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@redhat.com>
To: gdb-patches@sourceware.org
Subject: FYI: fix PR 11345
Date: Wed, 03 Mar 2010 18:04:00 -0000	[thread overview]
Message-ID: <m3mxyp703n.fsf@fleche.redhat.com> (raw)

I'm checking this in.

This fixes PR 11345.  The bug is that "%%" doesn't work if it appears
after the last format in a printf:

(gdb) printf "%%\n"
%%

The fix is to use printf, not puts, to print the rest of the format
string.  This is always ok because we know that there are no format
specifiers other than "%%" in the string.

The patch comes from the PR; it is small enough not to need papers.  I
wrote the test case and updated the comment in printf_command.

Built and regression tested on x86-64 (compile farm).

Tom

2010-03-03  Dainis Jonitis  <jonitis@gmail.com>

	PR gdb/11345:
	* printcmd.c (printf_command): Print end of format string using
	printf_filtered.

2010-03-03  Tom Tromey  <tromey@redhat.com>

	PR gdb/11345:
	* gdb.base/printcmds.exp (test_printf): Add test.

diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index c8cb35c..5e5ef8e 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -2642,8 +2642,11 @@ printf_command (char *arg, int from_tty)
 	/* Skip to the next substring.  */
 	current_substring += strlen (current_substring) + 1;
       }
-    /* Print the portion of the format string after the last argument.  */
-    puts_filtered (last_arg);
+    /* Print the portion of the format string after the last argument.
+       Note that this will not include any ordinary %-specs, but it
+       might include "%%".  That is why we use printf_filtered and not
+       puts_filtered here.  */
+    printf_filtered (last_arg);
   }
   do_cleanups (old_cleanups);
 }
diff --git a/gdb/testsuite/gdb.base/printcmds.exp b/gdb/testsuite/gdb.base/printcmds.exp
index 5598bde..9c2cd6b 100644
--- a/gdb/testsuite/gdb.base/printcmds.exp
+++ b/gdb/testsuite/gdb.base/printcmds.exp
@@ -686,6 +686,10 @@ proc test_printf {} {
 
     # Regression test for C lexer bug.
     gdb_test "printf \"%c\\n\", \"x\"\[1,0\]" "x"
+
+    # Regression test for "%% at end of format string.
+    # See http://sourceware.org/bugzilla/show_bug.cgi?id=11345
+    gdb_test "printf \"%%%d%%\\n\", 5" "%5%"
 }
 
 #Test printing DFP values with printf


             reply	other threads:[~2010-03-03 18:04 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-03 18:04 Tom Tromey [this message]
2010-03-03 18:22 ` Tom Tromey
2010-03-04  0:47 ` Pedro Alves
2010-03-04  2:35   ` Doug Evans
2010-03-04  2:43     ` Pedro Alves
2010-03-04  2:56       ` Doug Evans
2010-03-04  3:01         ` Pedro Alves
2010-03-04  2:36   ` Tom Tromey
2010-03-04 17:01   ` Tom Tromey
2010-03-04 17:20     ` Pedro Alves
2010-03-04 17:28       ` Doug Evans
2010-03-04 18:21         ` 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=m3mxyp703n.fsf@fleche.redhat.com \
    --to=tromey@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /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