summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Duerr <contact@christianduerr.com>2021-05-07 20:47:56 +0000
committerChristian Duerr <contact@christianduerr.com>2021-05-09 21:08:18 +0000
commitc5794d5b796ac964d071d7a18af1e8526bdb88ff (patch)
treed480edd1345f7c0e7b031b38e366f7eef4e9991a
parent706f476dee4f636ad5ce50e310f3a28e51987896 (diff)
downloadalacritty-c5794d5b796ac964d071d7a18af1e8526bdb88ff.tar.gz
alacritty-c5794d5b796ac964d071d7a18af1e8526bdb88ff.zip
Fix crash when copying out of bounds selections
Fixes #5067.
-rw-r--r--alacritty_terminal/src/selection.rs26
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
});
}