OSDN Git Service

Don't permit close of receive-only channel.
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 25 Oct 2011 16:35:24 +0000 (16:35 +0000)
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 25 Oct 2011 16:35:24 +0000 (16:35 +0000)
Better panic on attempt to close nil channel.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@180437 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/go/gofrontend/expressions.cc
libgo/runtime/go-close.c

index 180279e..cdf2bad 100644 (file)
@@ -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;
 
index 44533eb..778eab3 100644 (file)
@@ -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);