diff options
author | Christian Duerr <contact@christianduerr.com> | 2021-05-07 20:47:56 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-07 20:47:56 +0000 |
commit | 7f6b7acfeb016cbc47f68e5b2ccafae2395da92e (patch) | |
tree | c8c9f17b81489f9a06274fc1861856138eabe882 | |
parent | 8f4b752a988c80e27c06582363f6ebbf55ddbfca (diff) | |
download | alacritty-7f6b7acfeb016cbc47f68e5b2ccafae2395da92e.tar.gz alacritty-7f6b7acfeb016cbc47f68e5b2ccafae2395da92e.zip |
Fix crash when copying out of bounds selections
Fixes #5067.
-rw-r--r-- | alacritty_terminal/src/selection.rs | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/alacritty_terminal/src/selection.rs b/alacritty_terminal/src/selection.rs index e1ae7ed0..428b3f0e 100644 --- a/alacritty_terminal/src/selection.rs +++ b/alacritty_terminal/src/selection.rs @@ -11,7 +11,7 @@ use std::ops::{Bound, Range, RangeBounds}; use crate::ansi::CursorShape; use crate::grid::{Dimensions, GridCell, Indexed}; -use crate::index::{Column, Line, Point, Side}; +use crate::index::{Boundary, Column, Line, Point, Side}; use crate::term::cell::{Cell, Flags}; use crate::term::{RenderableCursor, Term}; @@ -274,6 +274,12 @@ impl Selection { mem::swap(&mut start, &mut end); } + // Clamp selection to within grid boundaries. + if end.point.line < term.topmost_line() { + return None; + } + start.point = start.point.grid_clamp(term, Boundary::Grid); + match self.ty { SelectionType::Simple => self.range_simple(start, end, columns), SelectionType::Block => self.range_block(start, end), @@ -507,11 +513,11 @@ mod tests { let mut selection = Selection::new(SelectionType::Lines, Point::new(Line(9), Column(1)), Side::Left); selection.update(Point::new(Line(4), Column(1)), Side::Right); - selection = selection.rotate(&size, &(Line(0)..Line(size.0 as i32)), 7).unwrap(); + selection = selection.rotate(&size, &(Line(0)..Line(size.0 as i32)), 4).unwrap(); assert_eq!(selection.to_range(&term(size.0, size.1)).unwrap(), SelectionRange { - start: Point::new(Line(-3), Column(0)), - end: Point::new(Line(2), Column(4)), + start: Point::new(Line(0), Column(0)), + end: Point::new(Line(5), Column(4)), is_block: false, }); } @@ -537,11 +543,11 @@ mod tests { let mut selection = Selection::new(SelectionType::Simple, Point::new(Line(9), Column(3)), Side::Right); selection.update(Point::new(Line(4), Column(1)), Side::Right); - selection = selection.rotate(&size, &(Line(0)..Line(size.0 as i32)), 7).unwrap(); + selection = selection.rotate(&size, &(Line(0)..Line(size.0 as i32)), 4).unwrap(); assert_eq!(selection.to_range(&term(size.0, size.1)).unwrap(), SelectionRange { - start: Point::new(Line(-3), Column(2)), - end: Point::new(Line(2), Column(3)), + start: Point::new(Line(0), Column(2)), + end: Point::new(Line(5), Column(3)), is_block: false, }); } @@ -552,11 +558,11 @@ mod tests { let mut selection = Selection::new(SelectionType::Block, Point::new(Line(9), Column(3)), Side::Right); selection.update(Point::new(Line(4), Column(1)), Side::Right); - selection = selection.rotate(&size, &(Line(0)..Line(size.0 as i32)), 7).unwrap(); + selection = selection.rotate(&size, &(Line(0)..Line(size.0 as i32)), 4).unwrap(); assert_eq!(selection.to_range(&term(size.0, size.1)).unwrap(), SelectionRange { - start: Point::new(Line(-3), Column(2)), - end: Point::new(Line(2), Column(3)), + start: Point::new(Line(0), Column(2)), + end: Point::new(Line(5), Column(3)), is_block: true }); } |