From 103dd06347bcecbaa807c438864eb747d464d745 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg <bensberg@justemail.net> Date: Sat, 16 Jul 2016 22:11:14 +0200 Subject: [PATCH] input: don't crash when the window is resized during verbatim input Instead of referring to a window that might have been deleted by a resize, just turn the keypad back on for the two windows from which input might have been requested. Also: don't insert KEY_WINCH as the verbatim keystroke. This fixes https://savannah.gnu.org/bugs/?48532. --- src/winio.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/winio.c b/src/winio.c index 5df57ae7..c5e5cce0 100644 --- a/src/winio.c +++ b/src/winio.c @@ -1375,8 +1375,12 @@ int *get_verbatim_kbinput(WINDOW *win, size_t *kbinput_len) * keypad back on if necessary now that we're done. */ if (ISSET(PRESERVE)) enable_flow_control(); - if (!ISSET(REBIND_KEYPAD)) - keypad(win, TRUE); + /* Use the global window pointers, because a resize may have freed + * the data that the win parameter points to. */ + if (!ISSET(REBIND_KEYPAD)) { + keypad(edit, TRUE); + keypad(bottomwin, TRUE); + } return retval; } @@ -1393,6 +1397,13 @@ int *parse_verbatim_kbinput(WINDOW *win, size_t *kbinput_len) while ((kbinput = get_input(win, 1)) == NULL) ; + /* When the window was resized, abort and return nothing. */ + if (*kbinput == KEY_WINCH) { + *kbinput_len = 0; + free(kbinput); + return NULL; + } + #ifdef ENABLE_UTF8 if (using_utf8()) { /* Check whether the first keystroke is a valid hexadecimal -- GitLab