From 0cb004734eeb56f17bf1a72bbbd8cda6c924173e Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 9 Jul 2026 20:29:51 -0700 Subject: [PATCH] terminal: ignore empty cell clears Screen.clearCells accepted a slice but its runtime safety validation indexed the first and last elements unconditionally. Passing an empty range therefore panicked before the otherwise valid no-op clear. Return immediately for an empty slice so validation and managed-memory bookkeeping only run when there are cells to clear. --- src/terminal/Screen.zig | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/terminal/Screen.zig b/src/terminal/Screen.zig index 95cba1bf9..8880e348c 100644 --- a/src/terminal/Screen.zig +++ b/src/terminal/Screen.zig @@ -1546,6 +1546,8 @@ pub fn clearCells( row: *Row, cells: []Cell, ) void { + if (cells.len == 0) return; + // This whole operation does unsafe things, so we just want to assert // the end state. page.pauseIntegrityChecks(true); @@ -4084,6 +4086,18 @@ test "Screen clearRows active styled line" { try testing.expectEqualStrings("", str); } +test "Screen clearCells empty range" { + const testing = std.testing; + + var s = try Screen.init(testing.allocator, .default); + defer s.deinit(); + + const page = s.cursor.page_pin.node.page(); + const row = s.cursor.page_row; + const cells = page.getCells(row); + s.clearCells(page, row, cells[0..0]); +} + test "Screen clearRows protected" { const testing = std.testing; const alloc = testing.allocator;