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.
This commit is contained in:
Mitchell Hashimoto
2026-07-09 20:29:51 -07:00
parent d6e24d9856
commit 0cb004734e

View File

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