From 3fb8efc8f2ea9bc33560c8c8681509a9a7fc95cd Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Fri, 22 Mar 2024 16:17:49 +0100 Subject: [PATCH] input: prevent 'macro_length' from underflowing when hammering M-: Normally, when recording a macro, users will make their keystrokes slowly and carefully, and will most likely wait to see the effect of the previous keystroke before making the next. So, the chances of two `recordmacro` keystrokes coming in in quick succession is normally nil. The 'macro_length' variable just needs a guard to prevent it from underflowing when someone is hammering the keys. This fixes https://savannah.gnu.org/bugs/?65394 in a better way. --- src/winio.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/winio.c b/src/winio.c index cf6fb0ca..d0ef2525 100644 --- a/src/winio.c +++ b/src/winio.c @@ -91,7 +91,8 @@ void add_to_macrobuffer(int code) /* Remove the last key code plus any leading Esc codes from macro buffer. */ void snip_last_keystroke(void) { - macro_length--; + if (macro_length > 0) + macro_length--; while (macro_length > 0 && macro_buffer[macro_length - 1] == '\x1b') macro_length--; }