From 28a50c7f51ea031f91b47421322be981a5a0d8a6 Mon Sep 17 00:00:00 2001 From: Shenghou Ma Date: Thu, 13 Dec 2012 23:48:48 +0800 Subject: [PATCH] runtime: deletion on nil maps is a no-op now Fixes #4535. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/6942044 --- src/pkg/runtime/hashmap.c | 2 +- test/fixedbugs/issue4535.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 test/fixedbugs/issue4535.go diff --git a/src/pkg/runtime/hashmap.c b/src/pkg/runtime/hashmap.c index 60c592184e..eec5c019a8 100644 --- a/src/pkg/runtime/hashmap.c +++ b/src/pkg/runtime/hashmap.c @@ -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 index 0000000000..4511393569 --- /dev/null +++ b/test/fixedbugs/issue4535.go @@ -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) +} -- 2.48.1