Skip to content

Scope nullable block guard detection to the matched guard body - #148

Merged
alxxjohn merged 1 commit into
mainfrom
alexj/fix-null-dereference-guard-issue
Aug 19, 2026
Merged

Scope nullable block guard detection to the matched guard body#148
alxxjohn merged 1 commit into
mainfrom
alexj/fix-null-dereference-guard-issue

Conversation

@alxxjohn

Copy link
Copy Markdown
Contributor

Motivation

  • The previous block-style null-guard helper scanned a fixed 3,000-byte window after if (!name) { and could credit an exit keyword that occurred outside the guard block, producing false negatives for defensive.null-assumption.
  • The intent is to ensure only exits that actually occur inside the matched null-check block suppress null-dereference findings while preserving nested-block support.

Description

  • Replace the 3,000-byte window scan in nullableParamHasBlockExitGuard with brace-depth tracking so the function locates the matching } and only searches for return|throw|continue|break inside that exact block in internal/codeguard/checks/quality/quality_defensive.go.
  • Preserve the existing single-line guard detection and the other guard heuristics in nullableParamGuarded while making the block-style check conservative for unclosed blocks.
  • Add focused regression tests in internal/codeguard/checks/quality/quality_defensive_test.go that validate exits inside the guard, exits after the guard (should not count), nested guard exits, and unclosed guard behavior.

Testing

  • Ran go test ./internal/codeguard/checks/quality ./tests/checks and the test suites completed successfully, including the new regression test file (tests passed).
  • Executed go test ./internal/codeguard/checks/quality to verify the package-level tests and the new unit tests, which passed.
  • Noted the repository szr wrapper was recommended by local AGENTS.md but was not available in the execution environment, so tests were run with the standard go test command.

Codex Task

@alxxjohn
alxxjohn merged commit f57d0f5 into main Aug 19, 2026
16 checks passed
@alxxjohn
alxxjohn deleted the alexj/fix-null-dereference-guard-issue branch August 19, 2026 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant