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.
pull/12907/head
zongyuan.li 2026-06-03 13:59:40 +08:00 committed by Zongyuan Li
parent 629838b9bd
commit 7fa6fffbca
1 changed files with 2 additions and 2 deletions

View File

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