]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: descriptive panics for use of nil map
authorRuss Cox <rsc@golang.org>
Thu, 17 Feb 2011 21:08:52 +0000 (16:08 -0500)
committerRuss Cox <rsc@golang.org>
Thu, 17 Feb 2011 21:08:52 +0000 (16:08 -0500)
R=r, r2
CC=golang-dev
https://golang.org/cl/4173060

src/pkg/runtime/hashmap.c

index f0d5ce90a7870a6a72fe98b5ac11f608ab734215..e50cefd9ab09a5e35d7f42b7fa42996374cec3b6 100644 (file)
@@ -781,6 +781,9 @@ runtime·mapaccess(Hmap *h, byte *ak, byte *av, bool *pres)
 {
        byte *res;
 
+       if(h == nil)
+               runtime·panicstring("lookup in nil map");
+
        if(runtime·gcwaiting)
                runtime·gosched();
 
@@ -802,6 +805,9 @@ runtime·mapaccess1(Hmap *h, ...)
        byte *ak, *av;
        bool pres;
 
+       if(h == nil)
+               runtime·panicstring("lookup in nil map");
+
        ak = (byte*)&h + h->ko1;
        av = (byte*)&h + h->vo1;
 
@@ -827,6 +833,9 @@ runtime·mapaccess2(Hmap *h, ...)
 {
        byte *ak, *av, *ap;
 
+       if(h == nil)
+               runtime·panicstring("lookup in nil map");
+
        ak = (byte*)&h + h->ko1;
        av = (byte*)&h + h->vo1;
        ap = (byte*)&h + h->po1;
@@ -852,6 +861,9 @@ runtime·mapassign(Hmap *h, byte *ak, byte *av)
        byte *res;
        int32 hit;
 
+       if(h == nil)
+               runtime·panicstring("assignment to entry in nil map");
+
        if(runtime·gcwaiting)
                runtime·gosched();
 
@@ -889,6 +901,9 @@ runtime·mapassign1(Hmap *h, ...)
 {
        byte *ak, *av;
 
+       if(h == nil)
+               runtime·panicstring("assignment to entry in nil map");
+
        ak = (byte*)&h + h->ko2;
        av = (byte*)&h + h->vo2;
 
@@ -902,6 +917,9 @@ runtime·mapassign2(Hmap *h, ...)
 {
        byte *ak, *av, *ap;
 
+       if(h == nil)
+               runtime·panicstring("assignment to entry in nil map");
+
        ak = (byte*)&h + h->ko2;
        av = (byte*)&h + h->vo2;
        ap = (byte*)&h + h->po2;