SDLControllerInterface: Prevent crash with out-of-range buttons

This commit is contained in:
Connor McLaughlin 2021-05-07 21:07:04 +10:00
parent e5a6103f74
commit 8a39969a61

View file

@ -629,6 +629,9 @@ bool SDLControllerInterface::HandleControllerAxisEvent(const SDL_ControllerAxisE
if (DoEventHook(Hook::Type::Axis, it->player_id, ev->axis, value)) if (DoEventHook(Hook::Type::Axis, it->player_id, ev->axis, value))
return true; return true;
if (ev->axis >= MAX_NUM_AXES)
return false;
const AxisCallback& cb = it->axis_mapping[ev->axis][AxisSide::Full]; const AxisCallback& cb = it->axis_mapping[ev->axis][AxisSide::Full];
if (cb) if (cb)
{ {
@ -707,6 +710,9 @@ bool SDLControllerInterface::HandleControllerButtonEvent(const SDL_ControllerBut
return true; return true;
} }
if (ev->button >= MAX_NUM_BUTTONS)
return false;
const ButtonCallback& cb = it->button_mapping[ev->button]; const ButtonCallback& cb = it->button_mapping[ev->button];
if (cb) if (cb)
{ {