From 2316b4442691e56a226e355273a5bbeb41e5ab8e Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Tue, 16 Jun 2020 18:02:39 +0100 Subject: [PATCH] Missing NULL check in swap_screen. Coverity points out that this function is mostly written as if it's intended to allow for term->screen and/or term->alt_screen to be NULL, but makes an unguarded call to find_last_nonempty_line on one of them. I don't immediately remember _why_ I needed to deal with those pointers being null, but it was probably a safety precaution against swap_screen being called during setup or during reconfiguration, in which case it seems sensible to keep it even if it's not needed in the _current_ state of the code. So, added the missing check. --- terminal.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/terminal.c b/terminal.c index 8f65a73e..08556d02 100644 --- a/terminal.c +++ b/terminal.c @@ -2066,7 +2066,9 @@ static void swap_screen(Terminal *term, int which, ttr = term->alt_screen; term->alt_screen = term->screen; term->screen = ttr; - term->alt_sblines = find_last_nonempty_line(term, term->alt_screen) + 1; + term->alt_sblines = ( + term->alt_screen ? + find_last_nonempty_line(term, term->alt_screen) + 1 : 0); t = term->curs.x; if (!reset && !keep_cur_pos) term->curs.x = term->alt_x;