Skip to content

Commit

Permalink
fix: prevent potential overflow during height computation
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Mar 10, 2024
1 parent 3a96651 commit 6d5e140
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion tui-react/src/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl List {
fn list_offset_for(&self, entry_in_view: Option<usize>, height: usize) -> usize {
match entry_in_view {
Some(pos) => match height as usize {
h if self.offset + h - 1 < pos => pos - h + 1,
h if self.offset + h.saturating_sub(1) < pos => pos.saturating_sub(h + 1),
_ if self.offset > pos => pos,
_ => self.offset,
},
Expand Down

0 comments on commit 6d5e140

Please sign in to comment.