Patchwork Go patch committed: Don't crash on tuple init from bad channel

login
register
mail settings
Submitter Ian Taylor
Date Dec. 15, 2010, 11:50 p.m.
Message ID <mcrzks6zjdd.fsf@google.com>
Download mbox | patch
Permalink /patch/75704/
State New
Headers show

Comments

Ian Taylor - Dec. 15, 2010, 11:50 p.m.
A tuple variable initialization from a channel expression, such as
	v, ok := <-c
could crash if the RHS was erroneous.  This patch fixes that.
Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.
Committed to mainline.

Ian

Patch

diff -r 8624179d2b0e go/gogo.cc
--- a/go/gogo.cc	Wed Dec 15 15:38:16 2010 -0800
+++ b/go/gogo.cc	Wed Dec 15 15:45:08 2010 -0800
@@ -3126,7 +3126,10 @@ 
   else if (expr->receive_expression() != NULL)
     {
       Expression* channel = expr->receive_expression()->channel();
-      return channel->type()->channel_type()->element_type();
+      Type* channel_type = channel->type();
+      if (channel_type->is_error_type())
+	return Type::make_error_type();
+      return channel_type->channel_type()->element_type();
     }
   else
     {