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] Avoid segfaulting on bad input


Hi!

The following patch fixes a typo in an error message and avoids segfaulting
on the enclosed testcase. Is it ok to commit or some other check is desired?

2000-09-01  Jakub Jelinek  <jakub@redhat.com>

	* c-decl.c (do_case): Fix a typo.
	* c-typeck.c (pop_init_level): If TYPE_SIZE_UNIT() is NULL as result
	of type layout error, avoid segfaulting.

	* gcc.dg/noncompile/20000901-1.c: New test.

--- gcc/c-decl.c.jj	Fri Sep  1 10:13:31 2000
+++ gcc/c-decl.c	Fri Sep  1 15:51:14 2000
@@ -6955,7 +6955,7 @@ do_case (low_value, high_value)
 	      error_with_decl (duplicate, "this is the first default label");
 	    }
 	  else
-	    error ("dupicate case value");
+	    error ("duplicate case value");
 	  if (high_value != NULL_TREE)
 	    error_with_decl (duplicate,
 			     "this is the first entry for that value");
--- gcc/testsuite/gcc.dg/noncompile/20000901-1.c.jj	Fri Sep  1 16:01:39 2000
+++ gcc/testsuite/gcc.dg/noncompile/20000901-1.c	Fri Sep  1 16:19:46 2000
@@ -0,0 +1 @@
+struct foo bar[] = { {"baz"} }; /* { dg-error "have incomplete type|excess elements|near" } */
--- gcc/c-typeck.c.jj	Fri Aug 25 14:22:08 2000
+++ gcc/c-typeck.c	Fri Sep  1 15:32:55 2000
@@ -5516,10 +5516,11 @@ pop_init_level (implicit)
 	    }
 
 	  filled
-	    = size_binop (MULT_EXPR, constructor_unfilled_index,
+	    = TYPE_SIZE_UNIT (TREE_TYPE (constructor_type)) ?
+	      size_binop (MULT_EXPR, constructor_unfilled_index,
 			  convert (bitsizetype,
 				   TYPE_SIZE_UNIT
-				   (TREE_TYPE (constructor_type))));
+				   (TREE_TYPE (constructor_type)))) : 0;
 	}
       else
 	filled = 0;

	Jakub

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