From e2baa6523875aaa13b6b7db80b7985978b8ee492 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Wed, 12 Apr 2023 16:39:54 +0200 Subject: [PATCH] =?UTF-8?q?render:=20ensure=20scroll=20region=E2=80=99s=20?= =?UTF-8?q?endpoint=20is=20valid=20after=20a=20window=20resize?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If we had a non-empty bottom scroll region, and the window was resized to a smaller size, the scroll region was not reset correctly. This led to a crash when scrolling the screen content. Fix by making sure the scroll region’s endpoint is within range. --- CHANGELOG.md | 2 ++ render.c | 3 +-- terminal.c | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8500195b..ca98ed5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,8 @@ ### Fixed * Incorrect icon in dock and window switcher on Gnome ([#1317][1317]) +* Crash when scrolling after resizing the window with non-zero + scrolling regions. [1317]: https://codeberg.org/dnkl/foot/issues/1317 diff --git a/render.c b/render.c index f16898b4..d39c9489 100644 --- a/render.c +++ b/render.c @@ -4128,8 +4128,7 @@ maybe_resize(struct terminal *term, int width, int height, bool force) if (term->scroll_region.start >= term->rows) term->scroll_region.start = 0; - - if (term->scroll_region.end >= old_rows) + if (term->scroll_region.end > term->rows) term->scroll_region.end = term->rows; term->render.last_cursor.row = NULL; diff --git a/terminal.c b/terminal.c index 04153513..2e62fbb7 100644 --- a/terminal.c +++ b/terminal.c @@ -2716,13 +2716,13 @@ term_scroll_partial(struct terminal *term, struct scroll_region region, int rows erase_line(term, row); } - term_damage_scroll(term, DAMAGE_SCROLL, region, rows); - term->grid->cur_row = grid_row(term->grid, term->grid->cursor.point.row); - #if defined(_DEBUG) for (int r = 0; r < term->rows; r++) xassert(grid_row(term->grid, r) != NULL); #endif + + term_damage_scroll(term, DAMAGE_SCROLL, region, rows); + term->grid->cur_row = grid_row(term->grid, term->grid->cursor.point.row); } void