This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


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

[PATCH] Fix tradcpp0's -Dfoo= handling


Hi!

The testcase below results in tradcpp0 ICE (regression against 2.95.x).
Basically, do_define is called with
buf == "DEFINE2DEFIN ???????????" and limit points to where the first
question mark is written. If for some reason there is a space at that place
(in the testcase this results from " 1" being appended to "DEFINE1DEFINE"
at the same place), bp > limit and collect_expansion abort()s. Even if the
abort was removed, it is a bad idea to go past buffer end.
Ok to commit, branch & head?

2001-05-01  Jakub Jelinek  <jakub@redhat.com>

	* tradcpp.c (do_define): Make sure we don't walk past limit.

	* gcc.dg/cpp/tr-define.c: New test.

--- gcc/testsuite/gcc.dg/cpp/tr-define.c.jj	Tue May  1 18:45:00 2001
+++ gcc/testsuite/gcc.dg/cpp/tr-define.c	Tue May  1 18:44:56 2001
@@ -0,0 +1,2 @@
+/* { dg-do preprocess } */
+/* { dg-options "-traditional -DDEFINE1DEFINE -DDEFINE2DEFIN=" } */
--- gcc/tradcpp.c.jj	Fri Mar 30 11:44:47 2001
+++ gcc/tradcpp.c	Tue May  1 18:41:14 2001
@@ -2670,8 +2670,8 @@ do_define (buf, limit, op)
       }
     }
 
-    ++bp;			/* skip paren */
-    while (is_nvspace (*bp))	/* and leading whitespace */
+    ++bp;					/* skip paren */
+    while (is_nvspace (*bp) && bp < limit)	/* and leading whitespace */
       ++bp;
     /* now everything from bp before limit is the definition. */
     defn = collect_expansion (bp, limit, argno, arg_ptrs);
@@ -2698,7 +2698,7 @@ do_define (buf, limit, op)
     }
   } else {
     /* simple expansion or empty definition; skip leading whitespace */
-    while (is_nvspace (*bp))
+    while (is_nvspace (*bp) && bp < limit)
       ++bp;
     /* now everything from bp before limit is the definition. */
     defn = collect_expansion (bp, limit, -1, 0);

	Jakub


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