From acd338ea33de36d223cc6d301712eed4a9501e6c Mon Sep 17 00:00:00 2001 From: Berke Güzel Date: Thu, 15 Oct 2026 11:31:50 +0300 Subject: Fix snapshot storage and allocation failure correctness Account for cluster records discarded by snapshot scrolling, propagate snapshot allocation failures with an empty retryable view, and allocate resized screens before mutating visible state. Add bounded-memory and allocation-failure regressions, and update the saved diagnostic and audit report. --- src/screen.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src/screen.c') diff --git a/src/screen.c b/src/screen.c index bd65564..1712faf 100644 --- a/src/screen.c +++ b/src/screen.c @@ -1236,6 +1236,14 @@ static bool term_resize_internal(struct term *t, int cols, int rows) int old_cols = active_scr->cols; int old_rows = active_scr->rows; + struct screen new_scr; + if (!resize_target(t, &new_scr, cols, rows, active_scr)) { + term_gstore_unpin(t->gstore); + return false; + } + + /* Allocate the replacement before scrolling rows into history. A + * failed height shrink must leave the active screen and cursor alone. */ if (rows < old_rows && t->cursor_y >= rows) { int shift = t->cursor_y - rows + 1; for (int i = 0; i < shift; i++) @@ -1243,12 +1251,10 @@ static bool term_resize_internal(struct term *t, int cols, int rows) t->cursor_y -= shift; t->saved.y = t->saved.y >= shift ? t->saved.y - shift : 0; } - - struct screen new_scr; - if (!resize_target(t, &new_scr, cols, rows, active_scr)) { - term_gstore_unpin(t->gstore); - return false; - } + /* Scrolling can advance the screen's history mapping when there is + * no history buffer, so capture its final value after the scroll. */ + new_scr.top_id = active_scr->top_id; + new_scr.top_seg = active_scr->top_seg; int pull = 0; if (rows > old_rows && !t->alternate) -- cgit v1.2.3