From 7fa6fffbca802897047186eed7b43faa3bcb87cf Mon Sep 17 00:00:00 2001 From: "zongyuan.li" Date: Wed, 3 Jun 2026 13:59:40 +0800 Subject: [PATCH] terminal: saturate cursor subtraction in resizeCols PageList.resize takes the .lt branch when columns shrink, which calls resizeWithoutReflow (mutating self.rows to the new smaller value) and then resizeCols with the original opts.cursor.y. When both axes shrink in one call and the cursor sits at or past the new bottom row, the expression `self.rows - c.y - 1` underflows and panics in safety builds. Use saturating subtraction; "remaining rows below cursor" is 0 once the cursor sits at or past the new bottom. --- src/terminal/PageList.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/terminal/PageList.zig b/src/terminal/PageList.zig index 8e5cd1934..dba3ca73f 100644 --- a/src/terminal/PageList.zig +++ b/src/terminal/PageList.zig @@ -1059,7 +1059,7 @@ fn resizeCols( break :cursor .{ .tracked_pin = c.pin orelse try self.trackPin(p), .untrack = c.pin == null, - .remaining_rows = self.rows - c.y - 1, + .remaining_rows = self.rows -| (c.y + 1), .wrapped_rows = wrapped, }; } else null; @@ -1192,7 +1192,7 @@ fn resizeCols( break :wrapped wrapped; }; - const current = self.rows - active_pt.active.y - 1; + const current = self.rows -| (active_pt.active.y + 1); var req_rows = c.remaining_rows; req_rows -|= wrapped -| c.wrapped_rows;