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 <tim@timculverhouse.com>
This commit is contained in:
Tim Culverhouse 2024-03-05 15:45:32 -06:00
parent 5560545b54
commit 778346feea

View file

@ -294,8 +294,10 @@ pub fn Vaxis(comptime T: type) type {
if (cell.char.width != 0) break :blk cell.char.width; if (cell.char.width != 0) break :blk cell.char.width;
const method: gwidth.Method = if (self.caps.unicode) .unicode else .wcwidth; 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; var j = i + 1;
while (j < i + w) : (j += 1) { while (j < i + w) : (j += 1) {
self.screen_last.buf[j].skipped = true; self.screen_last.buf[j].skipped = true;