From 68d02a19282e402031d39748ad88dc24da47562c Mon Sep 17 00:00:00 2001 From: root Date: Wed, 21 Jan 2026 13:50:54 +0400 Subject: [PATCH] fix: prevent cursor overflow with long input 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. --- src/ui/search_tui.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ui/search_tui.rs b/src/ui/search_tui.rs index f1c4a80..5d331e9 100644 --- a/src/ui/search_tui.rs +++ b/src/ui/search_tui.rs @@ -217,7 +217,10 @@ impl SearchTui { // Show cursor in input mode if self.mode == Mode::Input { - f.set_cursor_position((area.x + self.input.len() as u16 + 1, area.y + 1)); + // Calculate cursor position safely, constraining it to the input area + let max_input_width = area.width.saturating_sub(2); // borders + let input_len = self.input.len().min(max_input_width as usize) as u16; + f.set_cursor_position((area.x + input_len + 1, area.y + 1)); } }