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

View File

@ -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);
}
}