From ceac07b8db1c52a2bcfeb6762dc9d891538b9e69 Mon Sep 17 00:00:00 2001 From: Thomas Roessler Date: Mon, 26 Jul 1999 14:04:03 +0000 Subject: Dynamically allocate the unget buffer. Fixes Debian bug #41042. From Gero Treuner. --- curs_lib.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'curs_lib.c') diff --git a/curs_lib.c b/curs_lib.c index 1cb35d13..f9f50f68 100644 --- a/curs_lib.c +++ b/curs_lib.c @@ -34,9 +34,9 @@ * is impossible to unget function keys in SLang, so roll our own input * buffering routines. */ -static short UngetCount = 0; -#define UngetBufLen 128 -static event_t KeyEvent[UngetBufLen] = { {0,0} }; +static size_t UngetCount = 0; +static size_t UngetBufLen = 0; +static event_t *KeyEvent; void mutt_refresh (void) { @@ -372,9 +372,6 @@ int _mutt_enter_fname (const char *prompt, char *buf, size_t blen, int *redraw, return 0; } -/* FOO - this could be made more efficient by allocating/deallocating memory - * instead of using a fixed array - */ void mutt_ungetch (int ch, int op) { event_t tmp; @@ -382,8 +379,10 @@ void mutt_ungetch (int ch, int op) tmp.ch = ch; tmp.op = op; - if (UngetCount < UngetBufLen) /* make sure not to overflow */ - KeyEvent[UngetCount++] = tmp; + if (UngetCount >= UngetBufLen) + safe_realloc ((void **) &KeyEvent, (UngetBufLen += 128) * sizeof(event_t)); + + KeyEvent[UngetCount++] = tmp; } void mutt_flushinp (void) -- cgit v1.2.3