From 3c9157b1eca613a019d3dac08c22bea07967e0b1 Mon Sep 17 00:00:00 2001 From: oltolm Date: Fri, 9 Feb 2024 23:08:15 +0100 Subject: [PATCH] fix ASAN error in sdl_impl.cpp (#7427) --- src/input_common/sdl/sdl_impl.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/input_common/sdl/sdl_impl.cpp b/src/input_common/sdl/sdl_impl.cpp index 1e6d105d92..1833e49cb3 100644 --- a/src/input_common/sdl/sdl_impl.cpp +++ b/src/input_common/sdl/sdl_impl.cpp @@ -429,18 +429,20 @@ Common::ParamPackage SDLState::GetSDLControllerButtonBindByGUID( #if SDL_VERSION_ATLEAST(2, 0, 6) { - const SDL_ExtendedGameControllerBind extended_bind = - controller->bindings[mapped_button]; - if (extended_bind.input.axis.axis_max < extended_bind.input.axis.axis_min) { - params.Set("direction", "-"); - } else { - params.Set("direction", "+"); + if (mapped_button != SDL_CONTROLLER_BUTTON_INVALID) { + const SDL_ExtendedGameControllerBind extended_bind = + controller->bindings[mapped_button]; + if (extended_bind.input.axis.axis_max < extended_bind.input.axis.axis_min) { + params.Set("direction", "-"); + } else { + params.Set("direction", "+"); + } + params.Set("threshold", (extended_bind.input.axis.axis_min + + (extended_bind.input.axis.axis_max - + extended_bind.input.axis.axis_min) / + 2.0f) / + SDL_JOYSTICK_AXIS_MAX); } - params.Set( - "threshold", - (extended_bind.input.axis.axis_min + - (extended_bind.input.axis.axis_max - extended_bind.input.axis.axis_min) / 2.0f) / - SDL_JOYSTICK_AXIS_MAX); } #else params.Set("direction", "+"); // lacks extended_bind, so just a guess