From: Ian Lance Taylor Date: Tue, 25 Oct 2011 16:35:24 +0000 (+0000) Subject: Don't permit close of receive-only channel. X-Git-Tag: releases/gcc-4.7.0~2829 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=09367c0d60f551d7d05b6212b649a71636b623ce;p=thirdparty%2Fgcc.git Don't permit close of receive-only channel. Better panic on attempt to close nil channel. From-SVN: r180437 --- diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc index 180279efac65..cdf2bad09f3c 100644 --- a/gcc/go/gofrontend/expressions.cc +++ b/gcc/go/gofrontend/expressions.cc @@ -8153,6 +8153,8 @@ Builtin_call_expression::do_check_types(Gogo*) { if (this->one_arg()->type()->channel_type() == NULL) this->report_error(_("argument must be channel")); + else if (!this->one_arg()->type()->channel_type()->may_send()) + this->report_error(_("cannot close receive-only channel")); } break; diff --git a/libgo/runtime/go-close.c b/libgo/runtime/go-close.c index 44533ebe4c7f..778eab3d7d8f 100644 --- a/libgo/runtime/go-close.c +++ b/libgo/runtime/go-close.c @@ -16,6 +16,9 @@ __go_builtin_close (struct __go_channel *channel) { int i; + if (channel == NULL) + __go_panic_msg ("close of nil channel"); + i = pthread_mutex_lock (&channel->lock); __go_assert (i == 0);