From 5c30d39a69a4da5d011db4d52c15042561d53ce0 Mon Sep 17 00:00:00 2001 From: Andrew Burgess Date: Tue, 13 Aug 2013 16:05:23 +0000 Subject: [PATCH] Handle '#' flag for printf of pointer types. 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 | 5 +++++ gdb/common/format.c | 4 +++- gdb/testsuite/ChangeLog | 5 +++++ gdb/testsuite/gdb.base/printcmds.exp | 6 ++++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 22fb07caca4..99fa18b6d82 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2013-08-13 Andrew Burgess + + * common/format.c (parse_format_string): Don't allow '#' flag for + pointer arguments in format string. + 2013-08-13 Pierre Muller * src/gdb/utils.c (init_page_info): Only call tgetnum function diff --git a/gdb/common/format.c b/gdb/common/format.c index 1bdd2532d2f..985e0e4be55 100644 --- a/gdb/common/format.c +++ b/gdb/common/format.c @@ -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; diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 88680dbd2a2..0b60da5597e 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2013-08-13 Andrew Burgess + + * gdb.base/printcmds.exp (test_printf): Add test for printf of + pointer with various flags. + 2013-08-13 Tom Tromey * lib/cache.exp: New file. diff --git a/gdb/testsuite/gdb.base/printcmds.exp b/gdb/testsuite/gdb.base/printcmds.exp index 4f88382e813..60e4a7f574f 100644 --- a/gdb/testsuite/gdb.base/printcmds.exp +++ b/gdb/testsuite/gdb.base/printcmds.exp @@ -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 -- 2.30.2