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/parser: documentation: fset must be non-nil #16018

Closed
barrucadu opened this issue Jun 9, 2016 · 2 comments
Closed

go/parser: documentation: fset must be non-nil #16018

barrucadu opened this issue Jun 9, 2016 · 2 comments
Assignees
Milestone

Comments

@barrucadu
Copy link

@barrucadu barrucadu commented Jun 9, 2016

Please answer these questions before submitting your issue. Thanks!

  1. What version of Go are you using (go version)?
    go version go1.6.2 darwin/amd64
  2. What operating system and processor architecture are you using (go env)?
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/michaelwalker/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GO15VENDOREXPERIMENT="1"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"
  1. What did you do?
package main

import (
        "go/parser"
)

func main() {
        // This file must exist, or you get an `open` error before the issue happens.
        _, _ = parser.ParseFile(nil, "foo.go", nil, 0)
        panic("Aha!")
}
  1. What did you expect to see?
    A panic
  2. What did you see instead?
    The program terminates with no output.

After putting this through gdb, there's a segfault happening because the first parameter I am passing in to parser.ParseFile is nil. This surprises me in two ways: firstly, I generally expect to see "Program terminated due to SIGSEGV" or something when there's a segfault, without needing to resort to a debugger; and secondly the documentation doesn't say that this is invalid.

@LordAro
Copy link

@LordAro LordAro commented Jun 9, 2016

Cannot reproduce, fwiw


 > go version
go version go1.6.2 linux/amd64
 > go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH=""
GORACE=""
GOROOT="/usr/lib/go-1.6"
GOTOOLDIR="/usr/lib/go-1.6/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT="1"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
 > cat main.go 
package main

import (
    "go/parser"
    "runtime"
)

func main() {
    _, filename, _, _ := runtime.Caller(0) // Get itself
    _, _ = parser.ParseFile(nil, filename, nil, 0)
    panic("Aha!")
}
 > go run main.go 
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
    panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 pc=0x4779a3]

goroutine 1 [running]:
panic(0x51fb20, 0xc82000a110)
    /usr/lib/go-1.6/src/runtime/panic.go:481 +0x3e6
go/parser.ParseFile.func1(0xc82003bf10, 0xc820001080, 0xc82003bf18)
    /usr/lib/go-1.6/src/go/parser/interface.go:96 +0x6a
panic(0x51fb20, 0xc82000a110)
    /usr/lib/go-1.6/src/runtime/panic.go:443 +0x4e9
go/token.(*FileSet).AddFile(0x0, 0x5f4d60, 0x2f, 0xffffffffffffffff, 0xb7, 0x0)
    /usr/lib/go-1.6/src/go/token/position.go:364 +0x433
go/parser.(*parser).init(0xc820001080, 0x0, 0x5f4d60, 0x2f, 0xc820086000, 0xb7, 0x2b7, 0x0)
    /usr/lib/go-1.6/src/go/parser/parser.go:74 +0x4c
go/parser.ParseFile(0x0, 0x5f4d60, 0x2f, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
    /usr/lib/go-1.6/src/go/parser/interface.go:116 +0x199
main.main()
    /home/lordaro/dev/go/src/test/parsefile/main.go:10 +0x64
exit status 2
@LordAro
Copy link

@LordAro LordAro commented Jun 9, 2016

Regardless of the possible segfault, surely ParseFile should return an error, rather than a panic/nil pointer deref?

@ianlancetaylor ianlancetaylor changed the title go/parser (documentation?): fset must be non-nil go/parser: documentation: fset must be non-nil Jun 9, 2016
@ianlancetaylor ianlancetaylor added this to the Go1.8 milestone Jun 9, 2016
@gopherbot gopherbot closed this in e980a3d Jun 10, 2016
@golang golang locked and limited conversation to collaborators Jun 10, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.