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

staticcheck panics (nil pointer dereference) in CheckAllocationNilCheck with unnamed function #1268

Closed
stapelberg opened this issue May 9, 2022 · 2 comments
Labels

Comments

@stapelberg
Copy link

@stapelberg stapelberg commented May 9, 2022

Hey!

I just tracked an issue in staticcheck down to the following standalone reproducer:

% staticcheck -version
staticcheck 2022.1.1 (v0.3.1)
staticcheck -debug.version
% staticcheck -debug.version
staticcheck -debug.version
staticcheck 2022.1.1 (v0.3.1)

Compiled with Go version: go1.18
Main module:
	honnef.co/go/tools@v0.3.1 (sum: h1:1kJlrWJLkaGXgcaeosRXViwviqjI7nkBvU2+sZW0AYc=)
Dependencies:
	github.com/BurntSushi/toml@v0.4.1 (sum: h1:GaI7EiDXDRfa8VshkTj7Fym7ha+y8/XxIgD2okUIjLw=)
	golang.org/x/exp/typeparams@v0.0.0-20220218215828-6cf2b201936e (sum: h1:qyrTQ++p1afMkO4DPEeLGq/3oTsdlvdH4vqZUBWzUKM=)
	golang.org/x/mod@v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 (sum: h1:kQgndtyPBW/JIYERgdxfwMYh3AVStj88WQTlNDi2a+o=)
	golang.org/x/sys@v0.0.0-20211019181941-9d821ace8654 (sum: h1:id054HUawV2/6IGm2IV8KZQjqtwAOo2CYlOToYqa0d0=)
	golang.org/x/tools@v0.1.11-0.20220316014157-77aa08bb151a (sum: h1:ofrrl6c6NG5/IOSx/R1cyiQxxjqlur0h/TvbUhkH0II=)
	golang.org/x/xerrors@v0.0.0-20200804184101-5ec99f83aff1 (sum: h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=)
% go version
go version go1.18 linux/amd64
go env
% go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/michael/.cache/go-build"
GOENV="/home/michael/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/michael/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/michael/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/michael/sdk/go1.18"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/michael/sdk/go1.18/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1422223438=/tmp/go-build -gno-record-gcc-switches"

Steps to reproduce:

% cat > finder.go <<'EOT'
package main

import "io"

func initialize(*io.Reader) error { return nil }

func _() {
	var r io.Reader
	if err := initialize(&r); err != nil {
	}
}

func main() {
}
EOT

% staticcheck finder.go
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x80 pc=0x832176]

goroutine 447 [running]:
honnef.co/go/tools/go/ir.(*Function).debugInfo(...)
	/home/michael/go/pkg/mod/honnef.co/go/tools@v0.3.1/go/ir/func.go:684
honnef.co/go/tools/go/ir.(*Function).ValueForExpr(...)
	/home/michael/go/pkg/mod/honnef.co/go/tools@v0.3.1/go/ir/source.go:137
honnef.co/go/tools/staticcheck.CheckAllocationNilCheck.func1({0x9d1480?, 0xc0089e3e80?})
	/home/michael/go/pkg/mod/honnef.co/go/tools@v0.3.1/staticcheck/lint.go:5116 +0x1f6
golang.org/x/tools/go/ast/inspector.(*Inspector).Preorder(0xc0089ebea8, {0xc0085d65e8?, 0x1?, 0x0?}, 0xc00754fdf8)
	/home/michael/go/pkg/mod/golang.org/x/tools@v0.1.11-0.20220316014157-77aa08bb151a/go/ast/inspector/inspector.go:77 +0x9a
honnef.co/go/tools/analysis/code.Preorder(...)
	/home/michael/go/pkg/mod/honnef.co/go/tools@v0.3.1/analysis/code/visit.go:16
honnef.co/go/tools/staticcheck.CheckAllocationNilCheck(0xc008622820)
	/home/michael/go/pkg/mod/honnef.co/go/tools@v0.3.1/staticcheck/lint.go:5213 +0xdc
honnef.co/go/tools/lintcmd/runner.(*analyzerRunner).do(0xc008a23230, {0x9d4298?, 0xc008a21cc0})
	/home/michael/go/pkg/mod/honnef.co/go/tools@v0.3.1/lintcmd/runner/runner.go:1032 +0x614
honnef.co/go/tools/lintcmd/runner.genericHandle({0x9d4298?, 0xc008a21cc0}, {0x9d4298?, 0xc0089e83c0?}, 0x0?, 0xc0001759f0, 0xc008587c60)
	/home/michael/go/pkg/mod/honnef.co/go/tools@v0.3.1/lintcmd/runner/runner.go:857 +0x102
created by honnef.co/go/tools/lintcmd/runner.(*subrunner).runAnalyzers
	/home/michael/go/pkg/mod/honnef.co/go/tools@v0.3.1/lintcmd/runner/runner.go:1101 +0x705

Any idea what the issue might be and how to fix it?

Thanks!

@stapelberg stapelberg added bug needs-triage Newly filed issue that needs triage labels May 9, 2022
@dominikh dominikh added started Issues we've started working on and removed needs-triage Newly filed issue that needs triage labels May 9, 2022
@dominikh
Copy link
Owner

@dominikh dominikh commented May 9, 2022

What's triggering the bug is that the function's name is _.

@dominikh dominikh removed the started Issues we've started working on label May 9, 2022
@stapelberg
Copy link
Author

@stapelberg stapelberg commented May 9, 2022

Thanks for the quick fix!

dominikh added a commit that referenced this issue May 16, 2022
dominikh added a commit that referenced this issue May 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants