From a1b5862db21ab0ae52ba2e8314be46432eac5225 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 21 Feb 2020 23:35:43 +0100 Subject: [PATCH] scroll-up: ensure view is valid after adjusting an overshot scrollback When we scroll up, we need to ensure that we don't scroll too far, "past" the scrollback limit. I.e. we need to ensure we don't wrap around. The code did this. But, in certain scenarios, the resulting view points into uninitialized scrollback history. This happens when we haven't yet filled the entire scrollback, and scroll up enough lines to wrap around the scrollback. The old code would adjust the view for the wrap around, but doing so pointed the view at the not-yet utilized scrollback. --- commands.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/commands.c b/commands.c index 572dae68..53d0dfb3 100644 --- a/commands.c +++ b/commands.c @@ -55,6 +55,9 @@ cmd_scrollback_up(struct terminal *term, int rows) new_view = end + 1; } + while (term->grid->rows[new_view] == NULL) + new_view = (new_view + 1) % term->grid->num_rows; + #if defined(_DEBUG) for (int r = 0; r < term->rows; r++) assert(term->grid->rows[(new_view + r) % term->grid->num_rows] != NULL);