From 3d08161b5053ea8930b97232ab88486d2ff6a7bf Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 9 Jul 2026 20:50:23 -0700 Subject: [PATCH] terminal: handle empty tabstop ranges Tabstops.reset subtracted one from the column count before iterating default stops. Although init and resize accept zero columns, resetting that state with a nonzero interval underflowed and panicked. Return after clearing when the grid has fewer than two columns. Empty and single-column tabstop sets now preserve the normal no-stop result. --- src/terminal/Tabstops.zig | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/terminal/Tabstops.zig b/src/terminal/Tabstops.zig index 68138cbf8..8dbe67893 100644 --- a/src/terminal/Tabstops.zig +++ b/src/terminal/Tabstops.zig @@ -170,11 +170,11 @@ pub fn reset(self: *Tabstops, interval: usize) void { @memset(&self.prealloc_stops, 0); @memset(self.dynamic_stops, 0); - if (interval > 0) { - var i: usize = interval; - while (i < self.cols - 1) : (i += interval) { - self.set(i); - } + if (interval == 0 or self.cols <= 1) return; + + var i: usize = interval; + while (i < self.cols - 1) : (i += interval) { + self.set(i); } } @@ -230,6 +230,13 @@ test "Tabstops: interval" { try testing.expect(t.get(8)); } +test "Tabstops: interval with zero columns" { + var t: Tabstops = try init(testing.allocator, 0, 8); + defer t.deinit(testing.allocator); + + try testing.expectEqual(@as(usize, 0), t.cols); +} + test "Tabstops: count on 80" { // https://superuser.com/questions/710019/why-there-are-11-tabstops-on-a-80-column-console