Handle '#' flag for printf of pointer types.
authorAndrew Burgess <aburgess@broadcom.com>
Tue, 13 Aug 2013 16:05:23 +0000 (16:05 +0000)
committerAndrew Burgess <aburgess@broadcom.com>
Tue, 13 Aug 2013 16:05:23 +0000 (16:05 +0000)
  http://sourceware.org/ml/gdb-patches/2013-08/msg00340.html

gdb/ChangeLog

* common/format.c (parse_format_string): Don't allow '#' flag for
pointer arguments in format string.

gdb/testsuite/ChangeLog

* gdb.base/printcmds.exp (test_printf): Add test for printf of
pointer with various flags.

gdb/ChangeLog
gdb/common/format.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/printcmds.exp

index 22fb07caca4bde700bc5b517f93786d1420cc4b7..99fa18b6d827ceb6b90ba84e3bdc1a8c83928b00 100644 (file)
@@ -1,3 +1,8 @@
+2013-08-13  Andrew Burgess  <aburgess@broadcom.com>
+
+       * common/format.c (parse_format_string): Don't allow '#' flag for
+       pointer arguments in format string.
+
 2013-08-13  Pierre Muller  <muller@sourceware.org>
 
        * src/gdb/utils.c (init_page_info): Only call tgetnum function
index 1bdd2532d2f2cc8e1e5ae7f81dac0f9996b214dd..985e0e4be55a76e4619fb50162009303974d4cd8 100644 (file)
@@ -263,7 +263,9 @@ parse_format_string (const char **arg)
            this_argclass = ptr_arg;
            if (lcount || seen_h || seen_big_l)
              bad = 1;
-           if (seen_prec || seen_zero || seen_space || seen_plus)
+           if (seen_prec)
+             bad = 1;
+           if (seen_hash || seen_zero || seen_space || seen_plus)
              bad = 1;
            break;
 
index 88680dbd2a29c5e3a9b44fa8fafd88c3fb065481..0b60da5597e716a5fcb492dc76b95a4d1b449222 100644 (file)
@@ -1,3 +1,8 @@
+2013-08-13  Andrew Burgess  <aburgess@broadcom.com>
+
+       * gdb.base/printcmds.exp (test_printf): Add test for printf of
+       pointer with various flags.
+
 2013-08-13  Tom Tromey  <tromey@redhat.com>
 
        * lib/cache.exp: New file.
index 4f88382e8131111e540cb06bf42e81d4c694e26b..60e4a7f574f75d4d93e8c8f552194c3e9b3fc8aa 100644 (file)
@@ -734,6 +734,12 @@ proc test_printf {} {
     gdb_test "printf \"%.234\", 0" "Incomplete format specifier at end of format string"
     gdb_test "printf \"%-\", 0" "Incomplete format specifier at end of format string"
     gdb_test "printf \"%-23\", 0" "Incomplete format specifier at end of format string"
+
+    # Test for invalid printf flags on pointer types.
+    gdb_test "printf \"%#p\", 0" "Inappropriate modifiers to format specifier 'p' in printf"
+    gdb_test "printf \"% p\", 0" "Inappropriate modifiers to format specifier 'p' in printf"
+    gdb_test "printf \"%0p\", 0" "Inappropriate modifiers to format specifier 'p' in printf"
+    gdb_test "printf \"%+p\", 0" "Inappropriate modifiers to format specifier 'p' in printf"
 }
 
 #Test printing DFP values with printf