fix: crash if pos_to_width is given an out of range value

Possible with bad lsp diagnostics for example.
This commit is contained in:
CJ van den Berg 2024-12-18 16:08:51 +01:00
parent c0a9be21f5
commit 587b707069
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -175,7 +175,10 @@ pub const Leaf = struct {
} else { } else {
const bytes = metrics.egc_length(metrics, buf, &cols, abs_col); const bytes = metrics.egc_length(metrics, buf, &cols, abs_col);
buf = buf[bytes..]; buf = buf[bytes..];
pos.* -= bytes; if (pos.* >= bytes)
pos.* -= bytes
else
pos.* = 0;
} }
col += @intCast(cols); col += @intCast(cols);
abs_col += @intCast(cols); abs_col += @intCast(cols);