From c29cd8abb9e17c468843b097cb0d944ace6b2625 Mon Sep 17 00:00:00 2001 From: David Symonds Date: Sat, 5 Nov 2011 11:28:23 +1100 Subject: [PATCH] gofix: avoid panic on body-less functions in netudpgroup. R=rsc, r CC=golang-dev https://golang.org/cl/5347041 --- src/cmd/gofix/netudpgroup.go | 2 +- src/cmd/gofix/netudpgroup_test.go | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/cmd/gofix/netudpgroup.go b/src/cmd/gofix/netudpgroup.go index 12a2efa2878..b54beb0de31 100644 --- a/src/cmd/gofix/netudpgroup.go +++ b/src/cmd/gofix/netudpgroup.go @@ -30,7 +30,7 @@ func netudpgroup(f *ast.File) bool { fixed := false for _, d := range f.Decls { fd, ok := d.(*ast.FuncDecl) - if !ok { + if !ok || fd.Body == nil { continue } walk(fd.Body, func(n interface{}) { diff --git a/src/cmd/gofix/netudpgroup_test.go b/src/cmd/gofix/netudpgroup_test.go index 24f4abc167e..88c0e093fc1 100644 --- a/src/cmd/gofix/netudpgroup_test.go +++ b/src/cmd/gofix/netudpgroup_test.go @@ -28,6 +28,26 @@ func f() { err := x.JoinGroup(nil, gaddr) err = y.LeaveGroup(nil, gaddr) } +`, + }, + // Innocent function with no body. + { + Name: "netudpgroup.1", + In: `package main + +import "net" + +func f() + +var _ net.IP +`, + Out: `package main + +import "net" + +func f() + +var _ net.IP `, }, }