aboutsummaryrefslogtreecommitdiff
path: root/src/display.rs
diff options
context:
space:
mode:
authorChristian Duerr <chrisduerr@users.noreply.github.com>2018-03-13 07:07:40 +0100
committerJoe Wilm <jwilm@users.noreply.github.com>2018-03-12 23:07:40 -0700
commitb9ad0cfad30c6fd1328658d8195f552f24df6ff9 (patch)
tree396b4817804c008be4056096159627f5c525e489 /src/display.rs
parent1977215b0be083f26d7670ed9c7c837f156274ea (diff)
downloadalacritty-b9ad0cfad30c6fd1328658d8195f552f24df6ff9.tar.gz
alacritty-b9ad0cfad30c6fd1328658d8195f552f24df6ff9.zip
Prevent negative cell dimensions (#1181)
Prevent the cell dimensions from going below 1, this bug resulted in allocation of large amounts of memory in the scrollback PR but is also present on master. Currently the approach is to just `panic!`, however an `eprintln!` and `exit` could be an alternative too. I don't think it's realistic to check this at startup and it should have no performance impact since the failing method is only called once at startup. To make it a bit more clear what kind of values are accepted, the datatypes of offsets and paddings have also been changed so that these don't accept floats anymore and padding can never be negative. This should allow us to be a bit more strict with the config to make sure that errors are printed when invalid values are specified (like negative padding). This fixes #1167.
Diffstat (limited to 'src/display.rs')
-rw-r--r--src/display.rs15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/display.rs b/src/display.rs
index 418f616e..bd8ae401 100644
--- a/src/display.rs
+++ b/src/display.rs
@@ -178,8 +178,8 @@ impl Display {
height: viewport_size.height.0 as f32,
cell_width: cell_width as f32,
cell_height: cell_height as f32,
- padding_x: config.padding().x.floor(),
- padding_y: config.padding().y.floor(),
+ padding_x: config.padding().x as f32,
+ padding_y: config.padding().y as f32,
};
// Channel for resize events
@@ -238,10 +238,15 @@ impl Display {
// font metrics should be computed before creating the window in the first
// place so that a resize is not needed.
let metrics = glyph_cache.font_metrics();
- let cell_width = (metrics.average_advance + f64::from(font.offset().x)) as u32;
- let cell_height = (metrics.line_height + f64::from(font.offset().y)) as u32;
+ let cell_width = metrics.average_advance as f32 + font.offset().x as f32;
+ let cell_height = metrics.line_height as f32 + font.offset().y as f32;
- Ok((glyph_cache, cell_width as f32, cell_height as f32))
+ // Prevent invalid cell sizes
+ if cell_width < 1. || cell_height < 1. {
+ panic!("font offset is too small");
+ }
+
+ Ok((glyph_cache, cell_width.floor(), cell_height.floor()))
}
pub fn update_glyph_cache(&mut self, config: &Config) {