You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ifmyObject==nil {
t.Errorf("Commit is nil")
}
ifmyObject.Property!=tt.myObject.Property {
t.Errorf("Property is %s, want %s", myObject.Property, tt.myObject.Property)
}
Results in a possible nil pointer dereference finding, event though it cannot be reached.
// Errorf is equivalent to Logf followed by Fail.
A return after t.Errorf(…) solves the false positive.
Version of golangci-lint
$ golangci-lint --versiongolangci-lint has version 2.1.2 built with go1.24.2 from 00a561d9 on 2025-04-15T13:26:47Z
Configuration
golangci-lint run
Go environment
$ go version && go envgo version go1.24.2 linux/amd64AR='ar'CC='gcc'CGO_CFLAGS='-O2 -g'CGO_CPPFLAGS=''CGO_CXXFLAGS='-O2 -g'CGO_ENABLED='1'CGO_FFLAGS='-O2 -g'CGO_LDFLAGS='-O2 -g'CXX='g++'GCCGO='gccgo'GO111MODULE=''GOAMD64='v1'GOARCH='amd64'GOAUTH='netrc'GOBIN=''GOCACHE='/home/me/.cache/go-build'GOCACHEPROG=''GODEBUG=''GOENV='/home/me/.config/go/env'GOEXE=''GOEXPERIMENT=''GOFIPS140='off'GOFLAGS=''GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1198222687=/tmp/go-build -gno-record-gcc-switches'GOHOSTARCH='amd64'GOHOSTOS='linux'GOINSECURE=''GOMOD='/home/me/Projects/Private/my-project/go.mod'GOMODCACHE='/home/me/go/pkg/mod'GONOPROXY=''GONOSUMDB=''GOOS='linux'GOPATH='/home/me/go'GOPRIVATE=''GOPROXY='https://proxy.golang.org,direct'GOROOT='/usr/lib/go'GOSUMDB='sum.golang.org'GOTELEMETRY='local'GOTELEMETRYDIR='/home/me/.config/go/telemetry'GOTMPDIR=''GOTOOLCHAIN='auto'GOTOOLDIR='/usr/lib/go/pkg/tool/linux_amd64'GOVCS=''GOVERSION='go1.24.2'GOWORK=''PKG_CONFIG='pkg-config'
Verbose output of running
$ golangci-lint cache clean
$ golangci-lint run -vINFO golangci-lint has version 2.1.2 built with go1.24.2 from 00a561d9 on 2025-04-15T13:26:47ZINFO [config_reader] Config search paths: [./ /home/me/Projects/Private/my-project /home/me/Projects/Private /home/me/Projects /home/me /home /]INFO maxprocs: Leaving GOMAXPROCS=24: CPU quota undefinedINFO [goenv] Read go env for 2.225912ms: map[string]string{"GOCACHE":"/home/me/.cache/go-build", "GOROOT":"/usr/lib/go"}INFO [lintersdb] Active 5 linters: [errcheck govet ineffassign staticcheck unused]INFO [loader] Go packages loading at mode 8767 (deps|exports_file|files|name|compiled_files|imports|types_sizes) took 137.562801msINFO [runner/filename_unadjuster] Pre-built 0 adjustments in 780.138µsINFO [linters_context/goanalysis] analyzers took 10.960488329s with top 10 stages: buildir: 8.156271004s, inspect: 756.195203ms, fact_deprecated: 484.077887ms, ctrlflow: 350.497698ms, printf: 269.983204ms, fact_purity: 197.25655ms, nilness: 136.225035ms, tokenfileanalyzer: 131.613618ms, SA5012: 120.441995ms, typedness: 106.799104msINFO [runner] Processors filtering stat (in/out): invalid_issue: 2/2, path_relativity: 2/2, exclusion_paths: 2/2, diff: 2/2, max_from_linter: 2/2, path_shortener: 2/2, exclusion_rules: 2/2, uniq_by_line: 2/2, path_absoluter: 2/2, cgo: 2/2, nolint_filter: 2/2, fixer: 2/2, filename_unadjuster: 2/2, generated_file_filter: 2/2, max_per_file_from_linter: 2/2, max_same_issues: 2/2, source_code: 2/2, severity-rules: 2/2, path_prettifier: 2/2, sort_results: 2/2INFO [runner] processing took 193.472µs with stages: nolint_filter: 150.322µs, generated_file_filter: 17.74µs, source_code: 14.73µs, path_relativity: 2µs, uniq_by_line: 1.52µs, max_same_issues: 1.37µs, sort_results: 1.26µs, path_shortener: 630ns, cgo: 580ns, invalid_issue: 520ns, max_from_linter: 480ns, path_absoluter: 320ns, filename_unadjuster: 320ns, exclusion_rules: 310ns, max_per_file_from_linter: 290ns, exclusion_paths: 280ns, fixer: 270ns, path_prettifier: 250ns, diff: 210ns, severity-rules: 70nsINFO [runner] linters took 1.799597061s with stages: goanalysis_metalinter: 1.799362349sinternal/conventional/parse_test.go:108:7: SA5011(related information): this check suggests that the pointer can be nil (staticcheck) if commit == nil { ^internal/conventional/parse_test.go:114:14: SA5011: possible nil pointer dereference (staticcheck) if commit.Type != tt.commit.Type { ^2 issues:* staticcheck: 2INFO File cache stats: 1 entries of total size 4.6KiBINFO Memory: 21 samples, avg is 509.4MB, max is 834.8MBINFO Execution took 1.940518007s
A minimal reproducible example or link to a public repository
Welcome
typecheck
section of the FAQ.How did you install golangci-lint?
AUR
Description of the problem
Results in a possible nil pointer dereference finding, event though it cannot be reached.
A return after
t.Errorf(…)
solves the false positive.Version of golangci-lint
Configuration
golangci-lint run
Go environment
Verbose output of running
A minimal reproducible example or link to a public repository
https://gitlab.com/PlusMinus0/my-release-tools/-/blob/c0bf6b3734b0f146327dbb9a91f15bca6850eaa6/internal/conventional/parse_test.go
Validation
Supporter
The text was updated successfully, but these errors were encountered: