Fix key processing

Fixes buffer-underwrite crash on macOS when scancode is remapped to -1.
This commit is contained in:
Alexander Batalov 2022-10-08 12:32:50 +03:00
parent 4c1020af5f
commit e16659d96d
1 changed files with 10 additions and 1 deletions

View File

@ -1155,6 +1155,10 @@ void _GNW95_clear_time_stamps()
// 0x4C9E14 // 0x4C9E14
static void _GNW95_process_key(KeyboardData* data) 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]; data->key = gNormalizedQwertyKeys[data->key];
if (gVcrState == VCR_STATE_PLAYING) { if (gVcrState == VCR_STATE_PLAYING) {
@ -1163,7 +1167,7 @@ static void _GNW95_process_key(KeyboardData* data)
vcrStop(); vcrStop();
} }
} else { } else {
RepeatInfo* ptr = &(_GNW95_key_time_stamps[data->key]); RepeatInfo* ptr = &(_GNW95_key_time_stamps[scanCode]);
if (data->down == 1) { if (data->down == 1) {
ptr->tick = getTicks(); ptr->tick = getTicks();
ptr->repeatCount = 0; ptr->repeatCount = 0;
@ -1171,6 +1175,11 @@ static void _GNW95_process_key(KeyboardData* data)
ptr->tick = -1; ptr->tick = -1;
} }
// Ignore keys which were remapped to -1.
if (data->key == -1) {
return;
}
_kb_simulate_key(data); _kb_simulate_key(data);
} }
} }