[tools] go/analysis: avoid panics on multi-valued call arguments

0 views
Skip to first unread message

Madeline Kalil (Gerrit)

unread,
Aug 14, 2026, 12:45:36 PM (2 days ago) Aug 14
to shuang cui, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Alex Putman, golang...@luci-project-accounts.iam.gserviceaccount.com, Alan Donovan, Gopher Robot, golang-co...@googlegroups.com

Madeline Kalil submitted the change

Change information

Commit message:
go/analysis: avoid panics on multi-valued call arguments

Several analyzers access call arguments before checking the argument count.

A valid Go call such as:

net.Dial(dialArgs())

contains one AST argument even though dialArgs returns two values.
Similar cases occur with sort.Slice, strings.Index, and strings.HasPrefix.

Check the expected argument count before indexing call.Args.
Add regression tests covering hostport, slicessort, stringscut, and stringscutprefix.

Fixes golang/go#80842
Change-Id: I1c2e66544c733d52fd3e566b18b333472c6e7fa3
Reviewed-by: Alex Putman <apu...@golang.org>
Reviewed-by: Madeline Kalil <mka...@google.com>
Files:
  • M go/analysis/passes/hostport/hostport.go
  • M go/analysis/passes/hostport/testdata/src/a/a.go
  • M go/analysis/passes/hostport/testdata/src/a/a.go.golden
  • M go/analysis/passes/modernize/sortslice.go
  • M go/analysis/passes/modernize/stringscut.go
  • M go/analysis/passes/modernize/stringscutprefix.go
  • M go/analysis/passes/modernize/testdata/src/slicessort/slicessort.go
  • M go/analysis/passes/modernize/testdata/src/slicessort/slicessort.go.golden
  • M go/analysis/passes/modernize/testdata/src/stringscut/stringscut.go
  • M go/analysis/passes/modernize/testdata/src/stringscut/stringscut.go.golden
  • M go/analysis/passes/modernize/testdata/src/stringscutprefix/stringscutprefix.go
  • M go/analysis/passes/modernize/testdata/src/stringscutprefix/stringscutprefix.go.golden
Change size: M
Delta: 12 files changed, 108 insertions(+), 6 deletions(-)
Branch: refs/heads/master
Submit Requirements:
Open in Gerrit
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: merged
Gerrit-Project: tools
Gerrit-Branch: master
Gerrit-Change-Id: I1c2e66544c733d52fd3e566b18b333472c6e7fa3
Gerrit-Change-Number: 813721
Gerrit-PatchSet: 4
Gerrit-Owner: shuang cui <imc...@gmail.com>
Gerrit-Reviewer: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Alex Putman <apu...@golang.org>
Gerrit-Reviewer: Madeline Kalil <mka...@google.com>
Gerrit-Reviewer: shuang cui <imc...@gmail.com>
Gerrit-CC: Gopher Robot <go...@golang.org>
open
diffy
satisfied_requirement
Reply all
Reply to author
Forward
0 new messages