From 5e0ebb5d5f8442bf5f8287d9e3af2086546925ff Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Mon, 8 Mar 2021 02:48:18 +1000 Subject: [PATCH] SDLControllerInterface: Don't crash on unbound hat index --- .../sdl_controller_interface.cpp | 39 ++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/frontend-common/sdl_controller_interface.cpp b/src/frontend-common/sdl_controller_interface.cpp index ad7d25e69..1ccf93676 100644 --- a/src/frontend-common/sdl_controller_interface.cpp +++ b/src/frontend-common/sdl_controller_interface.cpp @@ -497,25 +497,28 @@ bool SDLControllerInterface::HandleJoystickHatEvent(const SDL_JoyHatEvent* event bool processed = false; - if (const ButtonCallback& cb = it->hat_button_mapping[event->hat][0]; cb) + if (event->hat < it->hat_button_mapping.size()) { - cb(event->value & SDL_HAT_UP); - processed = true; - } - if (const ButtonCallback& cb = it->hat_button_mapping[event->hat][1]; cb) - { - cb(event->value & SDL_HAT_RIGHT); - processed = true; - } - if (const ButtonCallback& cb = it->hat_button_mapping[event->hat][2]; cb) - { - cb(event->value & SDL_HAT_DOWN); - processed = true; - } - if (const ButtonCallback& cb = it->hat_button_mapping[event->hat][3]; cb) - { - cb(event->value & SDL_HAT_LEFT); - processed = true; + if (const ButtonCallback& cb = it->hat_button_mapping[event->hat][0]; cb) + { + cb(event->value & SDL_HAT_UP); + processed = true; + } + if (const ButtonCallback& cb = it->hat_button_mapping[event->hat][1]; cb) + { + cb(event->value & SDL_HAT_RIGHT); + processed = true; + } + if (const ButtonCallback& cb = it->hat_button_mapping[event->hat][2]; cb) + { + cb(event->value & SDL_HAT_DOWN); + processed = true; + } + if (const ButtonCallback& cb = it->hat_button_mapping[event->hat][3]; cb) + { + cb(event->value & SDL_HAT_LEFT); + processed = true; + } } return processed;