From e16659d96df97e73e75893ede49d8a345bdd60bf Mon Sep 17 00:00:00 2001 From: Alexander Batalov Date: Sat, 8 Oct 2022 12:32:50 +0300 Subject: [PATCH] Fix key processing Fixes buffer-underwrite crash on macOS when scancode is remapped to -1. --- src/input.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/input.cc b/src/input.cc index edd0172..9d61b69 100644 --- a/src/input.cc +++ b/src/input.cc @@ -1155,6 +1155,10 @@ void _GNW95_clear_time_stamps() // 0x4C9E14 static void _GNW95_process_key(KeyboardData* data) { + // Use originally pressed scancode, not qwerty-remapped one, for tracking + // timestamps, see usage from |_GNW95_process_message|. + int scanCode = data->key; + data->key = gNormalizedQwertyKeys[data->key]; if (gVcrState == VCR_STATE_PLAYING) { @@ -1163,7 +1167,7 @@ static void _GNW95_process_key(KeyboardData* data) vcrStop(); } } else { - RepeatInfo* ptr = &(_GNW95_key_time_stamps[data->key]); + RepeatInfo* ptr = &(_GNW95_key_time_stamps[scanCode]); if (data->down == 1) { ptr->tick = getTicks(); ptr->repeatCount = 0; @@ -1171,6 +1175,11 @@ static void _GNW95_process_key(KeyboardData* data) ptr->tick = -1; } + // Ignore keys which were remapped to -1. + if (data->key == -1) { + return; + } + _kb_simulate_key(data); } }