]> Cypherpunks repositories - gostls13.git/commitdiff
gofix: avoid panic on body-less functions in netudpgroup.
authorDavid Symonds <dsymonds@golang.org>
Sat, 5 Nov 2011 00:28:23 +0000 (11:28 +1100)
committerDavid Symonds <dsymonds@golang.org>
Sat, 5 Nov 2011 00:28:23 +0000 (11:28 +1100)
R=rsc, r
CC=golang-dev
https://golang.org/cl/5347041

src/cmd/gofix/netudpgroup.go
src/cmd/gofix/netudpgroup_test.go

index 12a2efa2878a37823027fbd7ab45e6df401ed8e1..b54beb0de31e26abfa4525c44982e97b7e0ac1e6 100644 (file)
@@ -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{}) {
index 24f4abc167e6efc30cc5cd7eb31f3f94eb24227f..88c0e093fc15374e53620c7a76cabe0522affe26 100644 (file)
@@ -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
 `,
        },
 }