Skip to content
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

go.tools/vet: panic: runtime error: invalid memory address or nil pointer dereference #7149

Closed
gopherbot opened this issue Jan 18, 2014 · 5 comments
Milestone

Comments

@gopherbot
Copy link
Contributor

by kenliz@cruzio.com:

go version go1.2 darwin/amd64

What steps will reproduce the problem?
If possible, include a link to a program on play.golang.org.

1. go vet <package path> # causes a panic: 
runtime.panic(0x20b5a0, 0x4a6999)
    /usr/local/go/src/pkg/runtime/panic.c:266 +0xb6
main.(*File).isStringer(0x2105f2000, 0x210640990, 0x210642320)
    /tmp/bindist142506725/src/code.google.com/p/go.tools/cmd/vet/main.go:458 +0x9b
main.(*File).prepStringerReceiver(0x2105f2000, 0x210640990)
    /tmp/bindist142506725/src/code.google.com/p/go.tools/cmd/vet/main.go:443 +0x31
main.(*File).walkFuncDecl(0x2105f2000, 0x210640990)
    /tmp/bindist142506725/src/code.google.com/p/go.tools/cmd/vet/main.go:436 +0x7e
main.(*File).Visit(0x2105f2000, 0x5732a0, 0x210640990, 0x5730f8, 0x2105f2000)
    /tmp/bindist142506725/src/code.google.com/p/go.tools/cmd/vet/main.go:373 +0x141
go/ast.Walk(0x5730f8, 0x2105f2000, 0x5732a0, 0x210640990)
    /usr/local/go/src/pkg/go/ast/walk.go:52 +0x58
go/ast.walkDeclList(0x5730f8, 0x2105f2000, 0x21060ac00, 0x3b, 0x40)
    /usr/local/go/src/pkg/go/ast/walk.go:38 +0x95
go/ast.Walk(0x5730f8, 0x2105f2000, 0x567da8, 0x2105df880)
    /usr/local/go/src/pkg/go/ast/walk.go:351 +0x2a52
main.(*File).walkFile(0x2105f2000, 0x2105abfc0, 0x26, 0x2105df880)
    /tmp/bindist142506725/src/code.google.com/p/go.tools/cmd/vet/main.go:356 +0x137
main.doPackage(0x7fff5fbffadc, 0x1d, 0x2105ed900, 0xa, 0x12, ...)
    /tmp/bindist142506725/src/code.google.com/p/go.tools/cmd/vet/main.go:255 +0xb5e
main.doPackageDir(0x7fff5fbffadc, 0x1d)
    /tmp/bindist142506725/src/code.google.com/p/go.tools/cmd/vet/main.go:192 +0x63e
main.visit(0x7fff5fbffadc, 0x1d, 0x55e748, 0x2105f3550, 0x0, ...)
    /tmp/bindist142506725/src/code.google.com/p/go.tools/cmd/vet/main.go:271 +0x153
path/filepath.walk(0x7fff5fbffadc, 0x1d, 0x55e748, 0x2105f3550, 0x2b2980, ...)
    /usr/local/go/src/pkg/path/filepath/path.go:341 +0x72
path/filepath.Walk(0x7fff5fbffadc, 0x1d, 0x2b2980, 0x2105ec120, 0x22106fedf0)
    /usr/local/go/src/pkg/path/filepath/path.go:380 +0xb7
main.walkDir(0x7fff5fbffadc, 0x1d)
    /tmp/bindist142506725/src/code.google.com/p/go.tools/cmd/vet/main.go:286 +0x3b
main.main()
    /tmp/bindist142506725/src/code.google.com/p/go.tools/cmd/vet/main.go:154 +0x64b

2. go install <package path> 
produces some compiler error messages:
installing
# gitHub.com/Ken1JF/ahgo/ah
src/gitHub.com/Ken1JF/ahgo/ah/board.go:232: invalid operation: col < MaxBoardSize
(mismatched types ColValue and uint8)
src/gitHub.com/Ken1JF/ahgo/ah/board.go:233: cannot use colLabels[col + ColValue(1)]
(type uint8) as type string in return argument
src/gitHub.com/Ken1JF/ahgo/ah/board.go:235: missing return at end of function
src/gitHub.com/Ken1JF/ahgo/ah/board.go:242: invalid operation: row < MaxBoardSize
(mismatched types RowValue and uint8)
src/gitHub.com/Ken1JF/ahgo/ah/board.go:245: missing return at end of function
src/gitHub.com/Ken1JF/ahgo/ah/board.go:267: cannot use nl (type NodeLocCR) as type
NodeLoc in function argument
src/gitHub.com/Ken1JF/ahgo/ah/board.go:268: too many arguments to return
src/gitHub.com/Ken1JF/ahgo/ah/board.go:278: cannot use int(nl) (type int) as type string
in function argument

3. I've attached the file

What is the expected output?

error messages

What do you see instead?

panic

Which compiler are you using (5g, 6g, 8g, gccgo)?

6g

Which operating system are you using?

darwin/amd64
Mac OS 10.7.5

Which version are you using?  (run 'go version')

go version go1.2 darwin/amd64

Please provide any additional information below.

Attachments:

  1. board.go (30721 bytes)
@gopherbot
Copy link
Contributor Author

Comment 1 by kenliz@cruzio.com:

panic in go vet <package path>
was caused by missing return value declaration:
func (nl NodeLocCR) String() {
should be
func (nl NodeLocCR) String() string {
function body had return statements with string value

@davecheney
Copy link
Contributor

Comment 2:

Confirmed, thanks for the reproduction.
% go tool vet board.go 
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x10 pc=0xf7a7]
goroutine 16 [running]:
runtime.panic(0x2531e0, 0x449879)
    /Users/dfc/go/src/pkg/runtime/panic.c:249 +0xba
main.(*File).isStringer(0x20852c180, 0x20851d2f0, 0x0)
    /Users/dfc/src/code.google.com/p/go.tools/cmd/vet/main.go:460 +0xb7
main.(*File).prepStringerReceiver(0x20852c180, 0x20851d2f0)
    /Users/dfc/src/code.google.com/p/go.tools/cmd/vet/main.go:445 +0x43
main.(*File).walkFuncDecl(0x20852c180, 0x20851d2f0)
    /Users/dfc/src/code.google.com/p/go.tools/cmd/vet/main.go:437 +0x7e
main.(*File).Visit(0x20852c180, 0x22084c3f70, 0x20851d2f0, 0x0, 0x0)
    /Users/dfc/src/code.google.com/p/go.tools/cmd/vet/main.go:374 +0x165
go/ast.Walk(0x22084c3dc8, 0x20852c180, 0x22084c3f70, 0x20851d2f0)
    /Users/dfc/go/src/pkg/go/ast/walk.go:52 +0x6a
go/ast.walkDeclList(0x22084c3dc8, 0x20852c180, 0x208541000, 0x3b, 0x40)
    /Users/dfc/go/src/pkg/go/ast/walk.go:38 +0xa9
go/ast.Walk(0x22084c3dc8, 0x20852c180, 0x22084c3558, 0x208501d80)
    /Users/dfc/go/src/pkg/go/ast/walk.go:351 +0x2ca2
main.(*File).walkFile(0x20852c180, 0x7fff5fbffcf4, 0x8, 0x208501d80)
    /Users/dfc/src/code.google.com/p/go.tools/cmd/vet/main.go:357 +0x14f
main.doPackage(0x27bd30, 0x1, 0x2084bc010, 0x1, 0x1, ...)
    /Users/dfc/src/code.google.com/p/go.tools/cmd/vet/main.go:256 +0xb6b
main.main()
    /Users/dfc/src/code.google.com/p/go.tools/cmd/vet/main.go:159 +0x739

Labels changed: added release-go1.3, repo-tools.

Status changed to Accepted.

@minux
Copy link
Member

minux commented Feb 24, 2014

Comment 3:

It's not a go/parser, go/types, etc. bug, so perhaps cc r is more appropriate
(according to the history of cmd/vet).

@robpike
Copy link
Contributor

robpike commented Feb 24, 2014

Comment 4:

Complete repro:
package ah
func (int) String() {
    return ""
}

@robpike
Copy link
Contributor

robpike commented Feb 24, 2014

Comment 5:

This issue was closed by revision golang/tools@ee3eeef.

Status changed to Fixed.

@rsc rsc added this to the Go1.3 milestone Apr 14, 2015
@rsc rsc removed the release-go1.3 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants