From 587b70706960d8cb6292ca8ef3953062bbfbf11d Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Wed, 18 Dec 2024 16:08:51 +0100 Subject: [PATCH] fix: crash if pos_to_width is given an out of range value Possible with bad lsp diagnostics for example. --- src/buffer/Buffer.zig | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/buffer/Buffer.zig b/src/buffer/Buffer.zig index 2ca5a5a..a5370b1 100644 --- a/src/buffer/Buffer.zig +++ b/src/buffer/Buffer.zig @@ -175,7 +175,10 @@ pub const Leaf = struct { } else { const bytes = metrics.egc_length(metrics, buf, &cols, abs_col); buf = buf[bytes..]; - pos.* -= bytes; + if (pos.* >= bytes) + pos.* -= bytes + else + pos.* = 0; } col += @intCast(cols); abs_col += @intCast(cols);