From fa4fced599d6f9aa76dc0028044d69e930800d0e Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Fri, 7 Oct 2022 09:04:37 -0700 Subject: [PATCH] validate the config to prevent div by 0 for initial_cols/initial_rows refs: https://github.com/wez/wezterm/issues/2593 --- config/src/config.rs | 12 ++++++++++-- docs/changelog.md | 2 ++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/config/src/config.rs b/config/src/config.rs index 0156100d7..b4fd69add 100644 --- a/config/src/config.rs +++ b/config/src/config.rs @@ -181,7 +181,7 @@ pub struct Config { pub set_environment_variables: HashMap, /// Specifies the height of a new window, expressed in character cells. - #[dynamic(default = "default_initial_rows")] + #[dynamic(default = "default_initial_rows", validate = "validate_row_or_col")] pub initial_rows: u16, #[dynamic(default = "default_true")] @@ -190,7 +190,7 @@ pub struct Config { pub enable_kitty_keyboard: bool, /// Specifies the width of a new window, expressed in character cells - #[dynamic(default = "default_initial_cols")] + #[dynamic(default = "default_initial_cols", validate = "validate_row_or_col")] pub initial_cols: u16, #[dynamic(default = "default_hyperlink_rules")] @@ -1656,6 +1656,14 @@ impl Default for ImePreeditRendering { } } +fn validate_row_or_col(value: u16) -> Result<(), String> { + if value < 1 { + Err("initial_cols and initial_rows must be non-zero".to_string()) + } else { + Ok(()) + } +} + fn validate_line_height(value: f64) -> Result<(), String> { if value <= 0.0 { Err(format!( diff --git a/docs/changelog.md b/docs/changelog.md index 9b0c82dcf..b3747422d 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -66,6 +66,8 @@ As features stabilize some brief notes about them will accumulate here. [#2548](https://github.com/wez/wezterm/issues/2548) * CharSelect panic when pressing enter when no matches were found [#2580](https://github.com/wez/wezterm/issues/2580) +* Panic when setting `initial_rows` or `initial_cols` to `0` + [2593](https://github.com/wez/wezterm/issues/2593) #### Changed * Removed Last Resort fallback font