]> Cypherpunks repositories - gostls13.git/commitdiff
allow range on nil maps
authorRuss Cox <rsc@golang.org>
Tue, 24 Mar 2009 01:32:37 +0000 (18:32 -0700)
committerRuss Cox <rsc@golang.org>
Tue, 24 Mar 2009 01:32:37 +0000 (18:32 -0700)
R=ken
OCL=26663
CL=26663

src/runtime/hashmap.c
test/map.go

index bb8dd7ba980a04ec4604fd36bbbf89fc0f24419c..b3022ca14948c8b106c1ec807dfc7e5814ff65a4 100644 (file)
@@ -870,6 +870,10 @@ sys·mapassign2(Hmap *h, ...)
 void
 sys·mapiterinit(Hmap *h, struct hash_iter *it)
 {
+       if(h == nil) {
+               it->data = nil;
+               return;
+       }
        hash_iter_init(h, it);
        it->data = hash_next(it);
        if(debug) {
index 085502bf521244fcdd85d5d787edfdb5043e0121..95da48c75d224ff5f71fcf63bed5b72b1e129b1f 100644 (file)
@@ -487,4 +487,10 @@ func main() {
                        fmt.Printf("update mipM[%d][%d] = %i\n", i, i, mipM[i][i]);
                }
        }
+       
+       // test range on nil map
+       var mnil map[string] int;
+       for x, y := range mnil {
+               panic("range mnil");
+       }
 }