From a6608152b986b5789790721e6487bac921ae29ed Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Sat, 7 Dec 2019 16:26:34 +1100 Subject: input_sdl.cpp: Ignore joystick buttons beyond maximum supported number. * Note that the code to map excess buttons to switches doesn't actually do anything useful while INPUT_MAX_BUTTONS and MAX_BUTTONS happen to be defined to the same number. --- src/osd/modules/input/input_sdl.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/osd/modules/input/input_sdl.cpp b/src/osd/modules/input/input_sdl.cpp index d7cd185aca8..596895e9e39 100644 --- a/src/osd/modules/input/input_sdl.cpp +++ b/src/osd/modules/input/input_sdl.cpp @@ -657,7 +657,8 @@ public: case SDL_JOYBUTTONDOWN: case SDL_JOYBUTTONUP: - joystick.buttons[sdlevent.jbutton.button] = (sdlevent.jbutton.state == SDL_PRESSED) ? 0x80 : 0; + if (sdlevent.jbutton.button < MAX_BUTTONS) + joystick.buttons[sdlevent.jbutton.button] = (sdlevent.jbutton.state == SDL_PRESSED) ? 0x80 : 0; break; } } @@ -1070,7 +1071,9 @@ public: } // loop over all buttons - for (int button = 0; button < SDL_JoystickNumButtons(joy); button++) + if (SDL_JoystickNumButtons(joy) > MAX_BUTTONS) + osd_printf_verbose("Joystick: ... Has %d buttons which exceeds supported %d buttons\n", SDL_JoystickNumButtons(joy), MAX_BUTTONS); + for (int button = 0; (button < MAX_BUTTONS) && (button < SDL_JoystickNumButtons(joy)); button++) { input_item_id itemid; -- cgit v1.2.3