Skip to content

Go: fix some duplicate results in go/index-out-of-bounds - #22678

Merged
owen-mc merged 3 commits into
github:mainfrom
owen-mc:go/fix/length-comparison-duplicates
Sep 28, 2026
Merged

owen-mc merged 3 commits into
github:mainfrom
owen-mc:go/fix/length-comparison-duplicates

Conversation

@owen-mc

@owen-mc owen-mc commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

When the result should be A and it is in a condition like A && B && C then we were creating results for A and A && B and A && B && C. This was caused by changes to guards in #22182. The fix is to only alert for the innermost condition. A test has been added to demonstrate the bug and show that it is fixed.

This does not need a change note as it is fixing FPs that haven't been in any release.

@owen-mc
owen-mc requested a review from a team September 24, 2026 13:09
@owen-mc
owen-mc requested a review from a team as a code owner September 24, 2026 13:09
@owen-mc owen-mc added the no-change-note-required This PR does not need a change note label Sep 24, 2026
Copilot AI balanced review requested due to automatic review settings September 24, 2026 13:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The focused guard filtering matches the intended behavior and is covered by an appropriate regression test.

Review effort: Balanced
Findings: None

What changed in this PR

Fixes duplicate go/index-out-of-bounds alerts by reporting only the innermost dominating guard.

Changes:

  • Filters out enclosing duplicate guards.
  • Adds a regression test for chained conditions.
  • Updates expected query results.
File Description
go/​ql/​src/​InconsistentCode/​LengthComparisonOffByOne.ql Selects the innermost applicable guard.
go/​ql/​test/​query-tests/​InconsistentCode/​LengthComparisonOffByOne/​main.go Adds the regression case.
go/​ql/​test/​query-tests/​InconsistentCode/​LengthComparisonOffByOne/​LengthComparisonOffByOne.expected Records the single expected alert.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-actions github-actions Bot added the Go label Sep 24, 2026

@michaelnebel michaelnebel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!
Is DCA needed?

@owen-mc
owen-mc merged commit e86d08b into github:main Sep 28, 2026
18 checks passed
@owen-mc
owen-mc deleted the go/fix/length-comparison-duplicates branch September 28, 2026 11:56
@owen-mc

owen-mc commented Sep 28, 2026

Copy link
Copy Markdown
Contributor Author

DCA showed nothing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Go no-change-note-required This PR does not need a change note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants