Patchwork Go patch committed: Don't crash if append arguments are erroneous

login
register
mail settings
Submitter Ian Taylor
Date Jan. 4, 2011, 10:54 p.m.
Message ID <mcrlj30nuun.fsf@google.com>
Download mbox | patch
Permalink /patch/77546/
State New
Headers show

Comments

Ian Taylor - Jan. 4, 2011, 10:54 p.m.
This patch to the Go frontend avoids a crash if the arguments to the
predeclared function append are erroneous.  It checks for errors before
assuming that the type of the first argument is a slice.  Bootstrapped
and ran Go testsuite on x86_64-unknown-linux-gnu.  Committed to
mainline.

Ian

Patch

diff -r 52053821a01d go/expressions.cc
--- a/go/expressions.cc	Tue Jan 04 14:36:50 2011 -0800
+++ b/go/expressions.cc	Tue Jan 04 14:50:55 2011 -0800
@@ -7965,14 +7965,14 @@ 
 	Expression* arg1 = args->front();
 	Expression* arg2 = args->back();
 
-	Array_type* at = arg1->type()->array_type();
-	Type* element_type = at->element_type();
-
 	tree arg1_tree = arg1->get_tree(context);
 	tree arg2_tree = arg2->get_tree(context);
 	if (arg1_tree == error_mark_node || arg2_tree == error_mark_node)
 	  return error_mark_node;
 
+	Array_type* at = arg1->type()->array_type();
+	Type* element_type = at->element_type();
+
 	arg2_tree = Expression::convert_for_assignment(context, at,
 						       arg2->type(),
 						       arg2_tree,