Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* RFA: fix macro expansion bug
@ 2008-12-11 21:37 Tom Tromey
  2008-12-11 23:05 ` Pedro Alves
  0 siblings, 1 reply; 10+ messages in thread
From: Tom Tromey @ 2008-12-11 21:37 UTC (permalink / raw)
  To: gdb-patches

This patch fixes a macro expansion bug pointed out by Pedro.

The bug is that get_pp_number incorrectly handles pp-number tokens
starting with '.'.  According to the C standard, it ought to only
accept '.' followed by a digit at the beginning of a pp-number.
However, it unconditionally accepts a leading '.'.

Built and regtested on x86-64 (compile farm).
Test case included.

Please review.

Tom

2008-12-11  Tom Tromey  <tromey@redhat.com>

	* macroexp.c (get_pp_number): Require digit after leading ".".

2008-12-11  Tom Tromey  <tromey@redhat.com>

	* gdb.base/macscp.exp: New regression test.

diff --git a/gdb/macroexp.c b/gdb/macroexp.c
index 7fb23ce..982df4d 100644
--- a/gdb/macroexp.c
+++ b/gdb/macroexp.c
@@ -278,7 +278,9 @@ get_pp_number (struct macro_buffer *tok, char *p, char *end)
 {
   if (p < end
       && (macro_is_digit (*p)
-          || *p == '.'))
+          || (*p == '.'
+	      && p + 2 <= end
+	      && macro_is_digit (p[1]))))
     {
       char *tok_start = p;
 
diff --git a/gdb/testsuite/gdb.base/macscp.exp b/gdb/testsuite/gdb.base/macscp.exp
index 9cb9ef5..40021b9 100644
--- a/gdb/testsuite/gdb.base/macscp.exp
+++ b/gdb/testsuite/gdb.base/macscp.exp
@@ -652,3 +652,11 @@ gdb_test "print str(maude)" \
 gdb_test "print xstr(maude)" \
   " = \"5\"" \
   "stringify with substitution"
+
+# Regression test for pp-number bug.
+gdb_test "macro define si_addr fields.fault.si_addr" \
+  "" \
+  "define si_addr macro"
+gdb_test "macro expand siginfo.si_addr" \
+  "expands to: siginfo. fields.fault.si_addr" \
+  "macro expand siginfo.si_addr"


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2008-12-12 17:07 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-12-11 21:37 RFA: fix macro expansion bug Tom Tromey
2008-12-11 23:05 ` Pedro Alves
2008-12-11 23:28   ` Tom Tromey
2008-12-11 23:35     ` Pedro Alves
2008-12-12 17:07       ` Tom Tromey
2008-12-11 23:31   ` Andreas Schwab
2008-12-11 23:41   ` Tom Tromey
2008-12-11 23:51     ` Pedro Alves
2008-12-11 23:58       ` Tom Tromey
2008-12-12 17:02       ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox