OSDN Git Service

Support nil maps.
[pf3gnuchains/gcc-fork.git] / libgo / runtime / go-map-index.c
index a387c4b..92a8068 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "go-alloc.h"
 #include "go-assert.h"
+#include "go-panic.h"
 #include "map.h"
 
 /* Rehash MAP to a larger size.  */
@@ -85,6 +86,13 @@ __go_map_index (struct __go_map *map, const void *key, _Bool insert)
   size_t bucket_index;
   char *entry;
 
+  if (map == NULL)
+    {
+      if (insert)
+       __go_panic_msg ("assignment to entry in nil map");
+      return NULL;
+    }
+
   descriptor = map->__descriptor;
 
   key_descriptor = descriptor->__map_descriptor->__key_type;