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

fix: panic with functions without body #29

Merged
merged 1 commit into from
Apr 20, 2024
Merged

Conversation

ldez
Copy link
Contributor

@ldez ldez commented Apr 20, 2024

In rare cases, functions don't have a body.

https://github.com/golang/go/blob/master/src/internal/syscall/unix/net.go

ERRO [runner] Panic: nonamedreturns: package "unix" (isInitialPkg: true, needAnalyzeSource: true): runtime error: invalid memory address or nil pointer dereference: goroutine 11202 [running]:
runtime/debug.Stack()
/usr/lib/go/src/runtime/debug/stack.go:24 +0x5e
github.com/golangci/golangci-lint/pkg/goanalysis.(*action).analyzeSafe.func1()
/home/ldez/sources/go/src/github.com/golangci/golangci-lint/pkg/goanalysis/runner_action.go:108 +0x277
panic({0x17ee9c0?, 0x2527420?})
/usr/lib/go/src/runtime/panic.go:770 +0x132
go/ast.Walk({0x1c47440?, 0xc008187ef0?}, {0x1c4cdd0, 0x0})
/usr/lib/go/src/go/ast/walk.go:234 +0x677
go/ast.Inspect(...)
/usr/lib/go/src/go/ast/walk.go:397
github.com/firefart/nonamedreturns/analyzer.findDeferWithVariableAssignment(0x0, 0xc007925320, {0x1c65160, 0xc00797f9e0})
/home/ldez/sources/go/pkg/mod/github.com/firefart/[email protected]/analyzer/analyzer.go:91 +0xb8
github.com/firefart/nonamedreturns/analyzer.run.func1({0x1c4bee8, 0xc007957f50})
/home/ldez/sources/go/pkg/mod/github.com/firefart/[email protected]/analyzer/analyzer.go:76 +0x2eb
golang.org/x/tools/go/ast/inspector.(*Inspector).Preorder(0xc006f79398, {0xc002fcac90?, 0x25568a0?, 0xc0000412c0?}, 0xc00140dcb0)
/home/ldez/sources/go/pkg/mod/golang.org/x/[email protected]/go/ast/inspector/inspector.go:82 +0x8f
github.com/firefart/nonamedreturns/analyzer.run(0xc00110bd40)
/home/ldez/sources/go/pkg/mod/github.com/firefart/[email protected]/analyzer/analyzer.go:41 +0x185
github.com/golangci/golangci-lint/pkg/goanalysis.(*action).analyze(0xc0027d17a0)
/home/ldez/sources/go/src/github.com/golangci/golangci-lint/pkg/goanalysis/runner_action.go:190 +0xa02
github.com/golangci/golangci-lint/pkg/goanalysis.(*action).analyzeSafe.func2()
/home/ldez/sources/go/src/github.com/golangci/golangci-lint/pkg/goanalysis/runner_action.go:112 +0x17
github.com/golangci/golangci-lint/pkg/timeutils.(*Stopwatch).TrackStage(0xc0031dab90, {0x19dfc59, 0xe}, 0xc002fcaf48)
/home/ldez/sources/go/src/github.com/golangci/golangci-lint/pkg/timeutils/stopwatch.go:111 +0x44
github.com/golangci/golangci-lint/pkg/goanalysis.(*action).analyzeSafe(0xc0018bc780?)
/home/ldez/sources/go/src/github.com/golangci/golangci-lint/pkg/goanalysis/runner_action.go:111 +0x7a
github.com/golangci/golangci-lint/pkg/goanalysis.(*loadingPackage).analyze.func2(0xc0027d17a0)
/home/ldez/sources/go/src/github.com/golangci/golangci-lint/pkg/goanalysis/runner_loadingpackage.go:80 +0xa8
created by github.com/golangci/golangci-lint/pkg/goanalysis.(*loadingPackage).analyze in goroutine 698
/home/ldez/sources/go/src/github.com/golangci/golangci-lint/pkg/goanalysis/runner_loadingpackage.go:75 +0x205
WARN [runner] Can't run linter goanalysis_metalinter: goanalysis_metalinter: nonamedreturns: package "unix" (isInitialPkg: true, needAnalyzeSource: true): runtime error: invalid memory address or nil pointer dereference

@firefart
Copy link
Owner

nice catch thanks!

@firefart firefart merged commit 3534a92 into firefart:main Apr 20, 2024
2 checks passed
@ldez ldez deleted the fix/panic branch April 20, 2024 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants