From adce0b9569e945ef3db81b292dbd5cc9efaa5065 Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 11 Sep 2015 15:12:21 -0300 Subject: [PATCH] Fix invalid key[] access in _handle_key_press() On Windows, if we pressed numpad dot key, all timers start working incorrectly (e.g. animations couldn't be reproduced anymore.). There was one report about this same issue on Mac OS X. --- src/allegro/src/keyboard.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/allegro/src/keyboard.c b/src/allegro/src/keyboard.c index e5650afec..ba7b29e33 100644 --- a/src/allegro/src/keyboard.c +++ b/src/allegro/src/keyboard.c @@ -439,6 +439,11 @@ void _handle_key_press(int keycode, int scancode) { ASSERT(keyboard_driver); + if (scancode < 0 || scancode >= KEY_MAX) { + TRACE(PREFIX_I "Scancode out of range %d pressed\n", scancode); + return; + } + if ((keyboard_driver->poll) || (!keyboard_polled)) { /* process immediately */ if (scancode > 0) { @@ -497,12 +502,8 @@ void _handle_key_release(int scancode) repeat_scan = -1; } - /* This is quite common if we press the numpad dot/delete. In debug - mode this asserts crashes the whole program. */ - /* ASSERT(scancode < KEY_MAX); */ - - if (scancode >= KEY_MAX) { - TRACE(PREFIX_I "Scancode out of range %d\n", scancode); + if (scancode < 0 || scancode >= KEY_MAX) { + TRACE(PREFIX_I "Scancode out of range %d released\n", scancode); return; }