From 62d43ddd63359f52fbd1df50d18bb2816b58397f Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Thu, 9 Aug 2018 00:04:28 -0700 Subject: [PATCH] avoid panic when some clients change scroll margins --- term/src/terminalstate.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/term/src/terminalstate.rs b/term/src/terminalstate.rs index a87de02fe..32520e73b 100644 --- a/term/src/terminalstate.rs +++ b/term/src/terminalstate.rs @@ -1494,8 +1494,11 @@ impl TerminalState { match cursor { Cursor::SetTopAndBottomMargins { top, bottom } => { let rows = self.screen().physical_rows; - let mut top = (top as i64).saturating_sub(1).min(rows as i64 - 1); - let mut bottom = (bottom as i64).saturating_sub(1).min(rows as i64 - 1); + let mut top = (top as i64).saturating_sub(1).min(rows as i64 - 1).max(0); + let mut bottom = (bottom as i64) + .saturating_sub(1) + .min(rows as i64 - 1) + .max(0); if top > bottom { std::mem::swap(&mut top, &mut bottom); }