summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2009-03-23 18:32:37 -0700
committerRuss Cox <rsc@golang.org>2009-03-23 18:32:37 -0700
commitd071d1916a77a05f69136db0694aef3eafc9b230 (patch)
tree0082f9d1b1e6adb4db63f2430cd84f8f82cd4ff6
parent6777c6dc218d3edbd87f91892a552566f01f9a58 (diff)
downloadgolang-d071d1916a77a05f69136db0694aef3eafc9b230.tar.gz
allow range on nil maps
R=ken OCL=26663 CL=26663
-rw-r--r--src/runtime/hashmap.c4
-rw-r--r--test/map.go6
2 files changed, 10 insertions, 0 deletions
diff --git a/src/runtime/hashmap.c b/src/runtime/hashmap.c
index bb8dd7ba9..b3022ca14 100644
--- a/src/runtime/hashmap.c
+++ b/src/runtime/hashmap.c
@@ -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) {
diff --git a/test/map.go b/test/map.go
index 085502bf5..95da48c75 100644
--- a/test/map.go
+++ b/test/map.go
@@ -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");
+ }
}