szn

Bug 372 — Resize vs region / saved-cursor invariants

372. Stale scroll region and saved cursor survive shrink

File: src/screen.zig (resize path) Severity: MEDIUM Status: ✅ FIXED

Fix (applied)

Screen.resize now clamps the DECSTBM scroll region into the new height (dropping it when degenerate, top >= bottom) and clamps both saved cursors (DECSC main + alternate) exactly like the live cursor.

Test: resize clamps scroll region and saved cursor — bug #372.

Problem

Resizing clamps the live cursor but leaves:

A later LF with origin mode, RI, or restore-cursor then indexes out of bounds or scrolls wrongly until the application reissues DECSTBM/DECSC. Fix as one invariant cleanup in resize(): clamp region to [0, height) with empty-region reset when degenerate, clamp saved cursor like the live one.

Reported together by the audit sweep as H4/H5 of the terminal-emulation review.