]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: fix defer of nil func
authorRuss Cox <rsc@golang.org>
Thu, 12 Jun 2014 20:34:36 +0000 (16:34 -0400)
committerRuss Cox <rsc@golang.org>
Thu, 12 Jun 2014 20:34:36 +0000 (16:34 -0400)
Fixes #8047.

LGTM=r, iant
R=golang-codereviews, r, iant
CC=dvyukov, golang-codereviews, khr
https://golang.org/cl/105140044

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

index 4b66e7dbaa26c0c82c0706546de6c60e958eb526..1f7c2eaadabe31c34d1db4220000daf79f478378 100644 (file)
@@ -856,7 +856,12 @@ runtime·newstack(void)
 void
 runtime·gostartcallfn(Gobuf *gobuf, FuncVal *fv)
 {
-       runtime·gostartcall(gobuf, fv->fn, fv);
+       void *fn;
+
+       fn = nil;
+       if(fv != nil)
+               fn = fv->fn;
+       runtime·gostartcall(gobuf, fn, fv);
 }
 
 // Maybe shrink the stack being used by gp.
diff --git a/test/fixedbugs/issue8047b.go b/test/fixedbugs/issue8047b.go
new file mode 100644 (file)
index 0000000..de6acaa
--- /dev/null
@@ -0,0 +1,22 @@
+// run
+
+// Copyright 2014 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.
+
+// Issue 8047. Defer setup during panic shouldn't crash for nil defer.
+
+package main
+
+func main() {
+       defer func() {
+               recover()
+       }()
+       f()
+}
+
+func f() {
+       var g func()
+       defer g()
+       panic(1)
+}