This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] Allow - in %p for printf


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=b8c2339b2f46d4885b933b832fc5b37c7ca101a6

commit b8c2339b2f46d4885b933b832fc5b37c7ca101a6
Author: Tom Tromey <tom@tromey.com>
Date:   Wed Feb 14 11:12:17 2018 -0700

    Allow - in %p for printf
    
    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-03-14  Tom Tromey  <tom@tromey.com>
    
    	PR cli/19918:
    	* printcmd.c (printf_pointer): Allow "-" in format.
    
    gdb/testsuite/ChangeLog
    2018-03-14  Tom Tromey  <tom@tromey.com>
    
    	PR cli/19918:
    	* gdb.base/printcmds.exp (test_printf): Add printf test using '-'
    	flag.

Diff:
---
 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/ChangeLog b/gdb/ChangeLog
index ba227ab..da59b39 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
 2018-03-14  Tom Tromey  <tom@tromey.com>
 
+	PR cli/19918:
+	* printcmd.c (printf_pointer): Allow "-" in format.
+
+2018-03-14  Tom Tromey  <tom@tromey.com>
+
 	* printcmd.c (_initialize_printcmd): Add usage to printf.
 
 2018-03-14  Yao Qi  <qiyao@sourceware.org>
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 13b967f..17c67ee 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 valid for pointers
+     -- see the format_pieces constructor.  */
+  while (*p == '-' || (*p >= '0' && *p < '9'))
     *fmt_p++ = *p++;
 
   gdb_assert (*p == 'p' && *(p + 1) == '\0');
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index c24ae5f..abac29f 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2018-03-14  Tom Tromey  <tom@tromey.com>
+
+	PR cli/19918:
+	* gdb.base/printcmds.exp (test_printf): Add printf test using '-'
+	flag.
+
 2018-03-08  Simon Marchi  <simon.marchi@ericsson.com>
 
 	PR gdb/22841
diff --git a/gdb/testsuite/gdb.base/printcmds.exp b/gdb/testsuite/gdb.base/printcmds.exp
index 9402d97..56cedb9 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]