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]
Other format: [Raw text]

[PATCH] Fix PR c/9262


Hi,

I really wonder how one can write such a broken code but a segfault is a 
little bit brutal and it's a regression from gcc 2.95.3 so...

The functions pushcase and pushcase_range from stmt.c (not used by the C and 
C++  front-ends) are guarded by a sanity check, while add_case_node (directly 
called by c-semantics.c) is not. I simply copy-n-pasted it from the formers 
to the latter.

Bootstrapped/regtested (c,c++,objc,f77 3.3 branch) on i586-redhat-linux-gnu. 
Ok for mainline and 3.3 ? for 3.2 too ?

-- 
Eric Botcazou


2003-02-07  Eric Botcazou  <ebotcazou@libertysurf.fr>

	PR c/9262
	* stmt.c (add_case_node): Check that we are inside a real case
	statement.


2003-02-07  Eric Botcazou  <ebotcazou@libertysurf.fr>

	* gcc.dg/switch-2.c: New test.
Index: stmt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/stmt.c,v
retrieving revision 1.276.2.2
diff -u -r1.276.2.2 stmt.c
--- stmt.c	21 Jan 2003 07:40:02 -0000	1.276.2.2
+++ stmt.c	6 Feb 2003 23:51:32 -0000
@@ -4666,6 +4666,10 @@
 {
   struct case_node *p, **q, *r;
 
+  /* Fail if not inside a real case statement.  */
+  if (! (case_stack && case_stack->data.case_stmt.start))
+    return 1;
+
   /* If there's no HIGH value, then this is not a case range; it's
      just a simple case label.  But that's just a degenerate case
      range.  */
/* PR c/9262 */
/* Originator: Rasmus Hahn <rassahah@neofonie.de> */
/* { dg-do compile } */

int foo(int i)
{
  switch (i)
    case 3:
      return 1,
    case 4:      /* { dg-error "parse error" } */
      return 2;
}

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