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.
This commit is contained in:
Mitchell Hashimoto
2026-07-09 20:50:23 -07:00
parent 8f1c2fe959
commit 3d08161b50

View File

@@ -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