From 778346feea77ae683727215124e8dbc37e5d5e1b Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Tue, 5 Mar 2024 15:45:32 -0600 Subject: [PATCH] render: fix handling of zero-width cells The render loop could get stuck in an infinite loop when it encounters a zero width cell. Always set the width to at least 1, and assert this. Signed-off-by: Tim Culverhouse --- src/vaxis.zig | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/vaxis.zig b/src/vaxis.zig index ca8b730..48fcf26 100644 --- a/src/vaxis.zig +++ b/src/vaxis.zig @@ -294,8 +294,10 @@ pub fn Vaxis(comptime T: type) type { if (cell.char.width != 0) break :blk cell.char.width; const method: gwidth.Method = if (self.caps.unicode) .unicode else .wcwidth; - break :blk gwidth.gwidth(cell.char.grapheme, method) catch 1; + const width = gwidth.gwidth(cell.char.grapheme, method) catch 1; + break :blk @max(1, width); }; + std.debug.assert(w > 0); var j = i + 1; while (j < i + w) : (j += 1) { self.screen_last.buf[j].skipped = true;