diff options
author | Keith Randall <khr@golang.org> | 2014-05-20 16:26:04 -0700 |
---|---|---|
committer | Keith Randall <khr@golang.org> | 2014-05-20 16:26:04 -0700 |
commit | cb6cb42ede03d6a35fbe6603f22e8855910f9f51 (patch) | |
tree | eb89bbb4f943fd38a0de9b18db1a248274fb59e8 | |
parent | a43669843b155ddb575d95acdb72dc62a1434efd (diff) | |
download | go-cb6cb42ede03d6a35fbe6603f22e8855910f9f51.tar.gz go-cb6cb42ede03d6a35fbe6603f22e8855910f9f51.zip |
reflect: don't panic on delete from nil map.
Fixes #8051
LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/95560046
-rw-r--r-- | src/pkg/reflect/all_test.go | 3 | ||||
-rw-r--r-- | src/pkg/runtime/hashmap.goc | 2 |
2 files changed, 4 insertions, 1 deletions
diff --git a/src/pkg/reflect/all_test.go b/src/pkg/reflect/all_test.go index 9c5eb4e554..e9949012c4 100644 --- a/src/pkg/reflect/all_test.go +++ b/src/pkg/reflect/all_test.go @@ -993,6 +993,9 @@ func TestNilMap(t *testing.T) { if x.Kind() != Invalid { t.Errorf("mbig.MapIndex(\"hello\") for nil map = %v, want Invalid Value", x) } + + // Test that deletes from a nil map succeed. + mv.SetMapIndex(ValueOf("hi"), Value{}) } func TestChan(t *testing.T) { diff --git a/src/pkg/runtime/hashmap.goc b/src/pkg/runtime/hashmap.goc index 36707c6ede..3327bed65e 100644 --- a/src/pkg/runtime/hashmap.goc +++ b/src/pkg/runtime/hashmap.goc @@ -990,7 +990,7 @@ func reflect·mapassign(t *MapType, h *Hmap, key *byte, val *byte) { #pragma textflag NOSPLIT func reflect·mapdelete(t *MapType, h *Hmap, key *byte) { if(h == nil) - runtime·panicstring("delete from nil map"); + return; // see bug 8051 if(raceenabled) { runtime·racewritepc(h, runtime·getcallerpc(&t), reflect·mapdelete); runtime·racereadobjectpc(key, t->key, runtime·getcallerpc(&t), reflect·mapdelete); |