Skip to content

fix: prevent potential panic in search navigation with empty results#60

Open
echobt wants to merge 1 commit intomainfrom
fix/issue-191
Open

fix: prevent potential panic in search navigation with empty results#60
echobt wants to merge 1 commit intomainfrom
fix/issue-191

Conversation

@echobt
Copy link
Copy Markdown
Contributor

@echobt echobt commented Jan 21, 2026

This PR fixes a potential race condition/panic in the TUI navigation logic.

Changes:

  • Used saturating_sub(1) instead of direct subtraction for results.len() - 1 in next() and previous() methods.
  • This ensures that even if results becomes empty between the initial check and the access (though unlikely in single-threaded contexts, it hardens the code against future changes or edge cases), the index calculation will not panic due to underflow.

Verification:

  • Verified via code inspection that logic handles len() == 0 safely (returning 0, which is handled gracefully by Ratatui or subsequent logic).
  • Ran existing tests (cargo test) to ensure no regressions.

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.

1 participant