summaryrefslogtreecommitdiff
path: root/alacritty_terminal/src/term/mod.rs
diff options
context:
space:
mode:
authorKirill Chibisov <wchibisovkirill@gmail.com>2019-09-26 15:44:59 +0300
committerChristian Duerr <contact@christianduerr.com>2019-09-26 14:44:59 +0200
commitad24485cdb5a2b6559185c3c41adbf6852e5ac80 (patch)
tree549c7f44d03b3bf6668406ab1d73f5660d73dd69 /alacritty_terminal/src/term/mod.rs
parentc1f089970fd3d4b9137d07647f8cd028b2b5b3a9 (diff)
downloadalacritty-ad24485cdb5a2b6559185c3c41adbf6852e5ac80.tar.gz
alacritty-ad24485cdb5a2b6559185c3c41adbf6852e5ac80.zip
Fix overflow on wrong scroll region setting
Fixes #2822.
Diffstat (limited to 'alacritty_terminal/src/term/mod.rs')
-rw-r--r--alacritty_terminal/src/term/mod.rs24
1 files changed, 18 insertions, 6 deletions
diff --git a/alacritty_terminal/src/term/mod.rs b/alacritty_terminal/src/term/mod.rs
index 11e0af45..6829c7d0 100644
--- a/alacritty_terminal/src/term/mod.rs
+++ b/alacritty_terminal/src/term/mod.rs
@@ -1260,8 +1260,7 @@ impl Term {
fn deccolm(&mut self) {
// Setting 132 column font makes no sense, but run the other side effects
// Clear scrolling region
- let scroll_region = Line(0)..self.grid.num_lines();
- self.set_scrolling_region(scroll_region);
+ self.set_scrolling_region(1, self.grid.num_lines().0);
// Clear grid
let template = self.cursor.template;
@@ -2118,10 +2117,23 @@ impl ansi::Handler for Term {
}
#[inline]
- fn set_scrolling_region(&mut self, region: Range<Line>) {
- trace!("Setting scrolling region: {:?}", region);
- self.scroll_region.start = min(region.start, self.grid.num_lines());
- self.scroll_region.end = min(region.end, self.grid.num_lines());
+ fn set_scrolling_region(&mut self, top: usize, bottom: usize) {
+ if top >= bottom {
+ debug!("Invalid scrolling region: ({};{})", top, bottom);
+ return;
+ }
+
+ // Bottom should be included in the range, but range end is not
+ // usually included. One option would be to use an inclusive
+ // range, but instead we just let the open range end be 1
+ // higher.
+ let start = Line(top - 1);
+ let end = Line(bottom);
+
+ trace!("Setting scrolling region: ({};{})", start, end);
+
+ self.scroll_region.start = min(start, self.grid.num_lines());
+ self.scroll_region.end = min(end, self.grid.num_lines());
self.goto(Line(0), Column(0));
}