New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: go list crashes when func Example has no body #28044

Closed
alandonovan opened this Issue Oct 5, 2018 · 3 comments

Comments

Projects
None yet
4 participants
@alandonovan
Contributor

alandonovan commented Oct 5, 2018

The underlying cause appears to be an unguarded nil dereference of ast.File.Body in go/doc.Examples.

$ cd $GOPATH/src
$ cat test/example_test.go
package test_test

func Example()

$ go version
go version devel +497fd2c09c Fri Oct 5 17:56:34 2018 +0000 linux/amd64
$ go list -test test
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x55bdb1]

goroutine 1 [running]:
go/ast.(*BlockStmt).Pos(...)
	/home/adonovan/go/src/go/ast/ast.go:728
go/doc.lastComment(0x0, 0x0, 0x0, 0x0, 0x558f94, 0xc000105444)
	/home/adonovan/go/src/go/doc/example.go:409 +0x11
go/doc.exampleOutput(0x0, 0x0, 0x0, 0x0, 0x1, 0xc000344cb8, 0x4f236d)
	/home/adonovan/go/src/go/doc/example.go:108 +0x4d
go/doc.Examples(0xc000344e38, 0x1, 0x1, 0x9, 0x0, 0x4)
	/home/adonovan/go/src/go/doc/example.go:75 +0x559
cmd/go/internal/load.(*testFuncs).load(0xc0000ba930, 0xc0004cc0c0, 0x3f, 0x976c2f, 0x6, 0xc0000ba98a, 0xc0000ba98b, 0xc000121010, 0x5c23bb)
	/home/adonovan/go/src/cmd/go/internal/load/test.go:530 +0x107
cmd/go/internal/load.loadTestFuncs(0xc0000ab680, 0x7, 0x0, 0x0)
	/home/adonovan/go/src/cmd/go/internal/load/test.go:417 +0x257
cmd/go/internal/load.TestPackagesFor(0xc0000ab680, 0x0, 0x1, 0xc00000e640, 0x1, 0x1, 0x21)
	/home/adonovan/go/src/cmd/go/internal/load/test.go:234 +0x18dd
cmd/go/internal/list.runList(0xd76880, 0xc00001e0f0, 0x1, 0x1)
	/home/adonovan/go/src/cmd/go/internal/list/list.go:449 +0x19a7
main.main()
	/home/adonovan/go/src/cmd/go/main.go:219 +0x843

@dmitshur dmitshur changed the title from go list: crash when func Example has no body to cmd/go: go list crashes when func Example has no body Oct 6, 2018

@dmitshur dmitshur added this to the Go1.12 milestone Oct 6, 2018

@dmitshur

This comment has been minimized.

Show comment
Hide comment
@dmitshur
Member

dmitshur commented Oct 6, 2018

@mfrw

This comment has been minimized.

Show comment
Hide comment
@mfrw

mfrw Oct 6, 2018

Contributor

Would it be a good idea if we skip the empty examples altogether?

Contributor

mfrw commented Oct 6, 2018

Would it be a good idea if we skip the empty examples altogether?

@gopherbot

This comment has been minimized.

Show comment
Hide comment
@gopherbot

gopherbot Oct 6, 2018

Change https://golang.org/cl/140317 mentions this issue: go/doc: skip exmples with no body

gopherbot commented Oct 6, 2018

Change https://golang.org/cl/140317 mentions this issue: go/doc: skip exmples with no body

@gopherbot gopherbot closed this in d30d5a6 Oct 9, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment