]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: deletion on nil maps is a no-op now
authorShenghou Ma <minux.ma@gmail.com>
Thu, 13 Dec 2012 15:48:48 +0000 (23:48 +0800)
committerShenghou Ma <minux.ma@gmail.com>
Thu, 13 Dec 2012 15:48:48 +0000 (23:48 +0800)
Fixes #4535.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6942044

src/pkg/runtime/hashmap.c
test/fixedbugs/issue4535.go [new file with mode: 0644]

index 60c592184e06665c82fcf9713726ff8d659a53df..eec5c019a84447367a0121fb273ae25facb4fb0d 100644 (file)
@@ -989,7 +989,7 @@ runtime·mapdelete(MapType *t, Hmap *h, ...)
        byte *ak;
 
        if(h == nil)
-               runtime·panicstring("deletion of entry in nil map");
+               return;
 
        if(raceenabled)
                runtime·racewritepc(h, runtime·getcallerpc(&t), runtime·mapdelete);
diff --git a/test/fixedbugs/issue4535.go b/test/fixedbugs/issue4535.go
new file mode 100644 (file)
index 0000000..4511393
--- /dev/null
@@ -0,0 +1,12 @@
+// run
+
+// Copyright 2012 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+func main() {
+       var m map[int]int
+       delete(m, 0)
+}