summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBurak Yigit Kaya <ben@byk.im>2019-11-14 02:36:54 +0300
committerChristian Duerr <contact@christianduerr.com>2019-11-14 00:36:54 +0100
commit561063b5606746936ee64d2f25a8b49c05a8d52e (patch)
treed5999b01b367d2eae8b2b55914290160666ead6f
parentd707e064a97532b36c68088ba44cd8a10f6f71dc (diff)
downloadalacritty-561063b5606746936ee64d2f25a8b49c05a8d52e.tar.gz
alacritty-561063b5606746936ee64d2f25a8b49c05a8d52e.zip
Fix division by zero without any cols or lines
The URL check uses a division to wrap column indices across lines, which will cause a runtime error if the size of the terminal is zero columns wide. Since a lot of our logic assumes that we at least have one column and line to work with and our behavior doesn't matter otherwise, this change fixes the terminal dimensions to have space for at least one cell.
-rw-r--r--alacritty/src/display.rs42
-rw-r--r--alacritty_terminal/src/term/mod.rs7
2 files changed, 21 insertions, 28 deletions
diff --git a/alacritty/src/display.rs b/alacritty/src/display.rs
index 53a5f47c..5c4c7313 100644
--- a/alacritty/src/display.rs
+++ b/alacritty/src/display.rs
@@ -186,14 +186,15 @@ impl Display {
info!("Cell Size: {} x {}", cell_width, cell_height);
info!("Padding: {} x {}", padding_x, padding_y);
+ // Create new size with at least one column and row
let size_info = SizeInfo {
dpr,
- width: viewport_size.width as f32,
- height: viewport_size.height as f32,
- cell_width: cell_width as f32,
- cell_height: cell_height as f32,
- padding_x: padding_x as f32,
- padding_y: padding_y as f32,
+ width: (viewport_size.width as f32).max(cell_width + 2. * padding_x),
+ height: (viewport_size.height as f32).max(cell_height + 2. * padding_y),
+ cell_width,
+ cell_height,
+ padding_x,
+ padding_y,
};
// Update OpenGL projection
@@ -302,25 +303,24 @@ impl Display {
self.update_glyph_cache(config, font);
}
- // Update the window dimensions
- if let Some(size) = update_pending.dimensions {
- self.size_info.width = size.width as f32;
- self.size_info.height = size.height as f32;
- }
-
- let dpr = self.size_info.dpr;
- let width = self.size_info.width;
- let height = self.size_info.height;
let cell_width = self.size_info.cell_width;
let cell_height = self.size_info.cell_height;
// Recalculate padding
- let mut padding_x = f32::from(config.window.padding.x) * dpr as f32;
- let mut padding_y = f32::from(config.window.padding.y) * dpr as f32;
+ let mut padding_x = f32::from(config.window.padding.x) * self.size_info.dpr as f32;
+ let mut padding_y = f32::from(config.window.padding.y) * self.size_info.dpr as f32;
+
+ // Update the window dimensions
+ if let Some(size) = update_pending.dimensions {
+ // Ensure we have at least one column and row
+ self.size_info.width = (size.width as f32).max(cell_width + 2. * padding_x);
+ self.size_info.height = (size.height as f32).max(cell_height + 2. * padding_y);
+ }
+ // Distribute excess padding equally on all sides
if config.window.dynamic_padding {
- padding_x = dynamic_padding(padding_x, width, cell_width);
- padding_y = dynamic_padding(padding_y, height, cell_height);
+ padding_x = dynamic_padding(padding_x, self.size_info.width, cell_width);
+ padding_y = dynamic_padding(padding_y, self.size_info.height, cell_height);
}
self.size_info.padding_x = padding_x.floor() as f32;
@@ -494,7 +494,7 @@ fn compute_cell_size(config: &Config, metrics: &font::Metrics) -> (f32, f32) {
let offset_x = f64::from(config.font.offset.x);
let offset_y = f64::from(config.font.offset.y);
(
- f32::max(1., ((metrics.average_advance + offset_x) as f32).floor()),
- f32::max(1., ((metrics.line_height + offset_y) as f32).floor()),
+ ((metrics.average_advance + offset_x) as f32).floor().max(1.),
+ ((metrics.line_height + offset_y) as f32).floor().max(1.),
)
}
diff --git a/alacritty_terminal/src/term/mod.rs b/alacritty_terminal/src/term/mod.rs
index 858402a4..063897cf 100644
--- a/alacritty_terminal/src/term/mod.rs
+++ b/alacritty_terminal/src/term/mod.rs
@@ -1023,13 +1023,6 @@ impl<T> Term<T> {
/// Resize terminal to new dimensions
pub fn resize(&mut self, size: &SizeInfo) {
- // Bounds check; lots of math assumes width and height are > 0
- if size.width as usize <= 2 * size.padding_x as usize
- || size.height as usize <= 2 * size.padding_y as usize
- {
- return;
- }
-
let old_cols = self.grid.num_cols();
let old_lines = self.grid.num_lines();
let mut num_cols = size.cols();