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]
Other format: [Raw text]

[gccgo] Better panic messages for send/receive on nil channel


Right now a send or receive on a nil channel will give a panic due to a
segmentation violation.  This patch adds checks for the condition and
gives a more relevant panic message.  Committed to gccgo branch.

Ian

diff -r 6cb25c0c5893 libgo/runtime/go-rec-big.c
--- a/libgo/runtime/go-rec-big.c	Tue Aug 31 10:07:49 2010 -0700
+++ b/libgo/runtime/go-rec-big.c	Tue Aug 31 11:06:24 2010 -0700
@@ -6,6 +6,7 @@
 
 #include <stdint.h>
 
+#include "go-panic.h"
 #include "channel.h"
 
 void
@@ -14,6 +15,9 @@
   size_t alloc_size;
   size_t offset;
 
+  if (channel == NULL)
+    __go_panic_msg ("receive from nil channel");
+
   alloc_size = ((channel->element_size + sizeof (uint64_t) - 1)
 		/ sizeof (uint64_t));
 
diff -r 6cb25c0c5893 libgo/runtime/go-rec-small.c
--- a/libgo/runtime/go-rec-small.c	Tue Aug 31 10:07:49 2010 -0700
+++ b/libgo/runtime/go-rec-small.c	Tue Aug 31 11:06:24 2010 -0700
@@ -273,6 +273,9 @@
 {
   uint64_t ret;
 
+  if (channel == NULL)
+    __go_panic_msg ("receive from nil channel");
+
   __go_assert (channel->element_size <= sizeof (uint64_t));
 
   if (!__go_receive_acquire (channel, for_select))
diff -r 6cb25c0c5893 libgo/runtime/go-send-big.c
--- a/libgo/runtime/go-send-big.c	Tue Aug 31 10:07:49 2010 -0700
+++ b/libgo/runtime/go-send-big.c	Tue Aug 31 11:06:24 2010 -0700
@@ -6,6 +6,7 @@
 
 #include <stdint.h>
 
+#include "go-panic.h"
 #include "channel.h"
 
 void
@@ -14,6 +15,9 @@
   size_t alloc_size;
   size_t offset;
 
+  if (channel == NULL)
+    __go_panic_msg ("send to nil channel");
+
   alloc_size = ((channel->element_size + sizeof (uint64_t) - 1)
 		/ sizeof (uint64_t));
 
diff -r 6cb25c0c5893 libgo/runtime/go-send-small.c
--- a/libgo/runtime/go-send-small.c	Tue Aug 31 10:07:49 2010 -0700
+++ b/libgo/runtime/go-send-small.c	Tue Aug 31 11:06:24 2010 -0700
@@ -151,6 +151,9 @@
 void
 __go_send_small (struct __go_channel *channel, uint64_t val, _Bool for_select)
 {
+  if (channel == NULL)
+    __go_panic_msg ("send to nil channel");
+
   __go_assert (channel->element_size <= sizeof (uint64_t));
 
   if (!__go_send_acquire (channel, for_select))

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