From 395fee2b01d0fe59f5502402e102f50ebfd88cd1 Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Sun, 17 May 2020 15:32:06 +0000 Subject: [PATCH] Fix crash when writing wide char in last column This resolves an issue where trying to write a fullwidth character in the last column would crash Alacritty, if linewrapping was disabled. Instead of assuming that the linewrap put after the linewrapping spacer was successful, the character writing is now skipped completely when trying to put a wide character in the last column. --- CHANGELOG.md | 1 + alacritty_terminal/src/term/mod.rs | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bd135f..510d0e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix escapes prematurely terminated by terminators in unicode glyphs - Incorrect location when clicking inside an unfocused window on macOS - Startup mode `Maximized` on Windows +- Crash when writing a fullwidth character in the last column with auto-wrap mode disabled ## 0.4.2 diff --git a/alacritty_terminal/src/term/mod.rs b/alacritty_terminal/src/term/mod.rs index 040c722..d575942 100644 --- a/alacritty_terminal/src/term/mod.rs +++ b/alacritty_terminal/src/term/mod.rs @@ -1462,10 +1462,16 @@ impl Handler for Term { if width == 1 { self.write_at_cursor(c); } else { - // Insert extra placeholder before wide char if glyph doesn't fit in this row anymore. if self.cursor.point.col + 1 >= num_cols { - self.write_at_cursor(' ').flags.insert(Flags::WIDE_CHAR_SPACER); - self.wrapline(); + if self.mode.contains(TermMode::LINE_WRAP) { + // Insert placeholder before wide char if glyph does not fit in this row. + self.write_at_cursor(' ').flags.insert(Flags::WIDE_CHAR_SPACER); + self.wrapline(); + } else { + // Prevent out of bounds crash when linewrapping is disabled. + self.input_needs_wrap = true; + return; + } } // Write full width glyph to current cursor cell.