Skip to content

Commit f3df454

Browse files
committed
fix(tui): prevent usize to u16 overflow in interactive renderer
1 parent de6da50 commit f3df454

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/cortex-tui/src/interactive/renderer.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,13 @@ impl<'a> InteractiveWidget<'a> {
109109
let hints_height = 1;
110110
let border_height = 2;
111111

112-
(items_count as u16) + header_height + search_height + hints_height + border_height
112+
// Use saturating conversion to prevent overflow when items_count exceeds u16::MAX
113+
let items_height = u16::try_from(items_count).unwrap_or(u16::MAX);
114+
items_height
115+
.saturating_add(header_height)
116+
.saturating_add(search_height)
117+
.saturating_add(hints_height)
118+
.saturating_add(border_height)
113119
}
114120
}
115121

0 commit comments

Comments
 (0)