Skip to content

fix: prevent cursor overflow with long input#59

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

fix: prevent cursor overflow with long input#59
echobt wants to merge 1 commit intomainfrom
fix/issue-190

Conversation

@echobt
Copy link
Copy Markdown
Contributor

@echobt echobt commented Jan 21, 2026

Description

This PR addresses an issue where extremely long input strings in the search TUI could cause an integer overflow when calculating the cursor position. The cursor position calculation now clamps the input length to the visible input area width, ensuring it fits within u16 and remains within the bounds of the terminal area.

Changes

  • Updated search_tui.rs to calculate max_input_width based on area width minus borders.
  • Clamped input_len to the minimum of the actual input length and max_input_width, casting strictly to u16 only after clamping.
  • Updated set_cursor_position to use the safe, clamped value.

Verification

  • Verified manually with a reproduction test case that simulated the overflow condition.
  • The cursor is now correctly positioned at the end of the visible input area even when the input string exceeds u16::MAX.

This change constrains the cursor position to the visible input area, preventing integer overflow when the input string is longer than the visible area or u16::MAX.
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