From a26f8fbd6c5d553db48e88fe8170a40942095bb9 Mon Sep 17 00:00:00 2001 From: mitchellcairns Date: Sun, 22 Jun 2025 19:17:02 -0700 Subject: [PATCH] Update SDL_hidapi_switch.c Assign NULL to pLeftStickCal and pRightStickCal pointer, and check for NULL-ness before proceeding otherwise return false as a safety check. --- src/joystick/hidapi/SDL_hidapi_switch.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/joystick/hidapi/SDL_hidapi_switch.c b/src/joystick/hidapi/SDL_hidapi_switch.c index fa4126d0f8..36865508b4 100644 --- a/src/joystick/hidapi/SDL_hidapi_switch.c +++ b/src/joystick/hidapi/SDL_hidapi_switch.c @@ -928,8 +928,8 @@ static bool SetIMUEnabled(SDL_DriverSwitch_Context *ctx, bool enabled) static bool LoadStickCalibration(SDL_DriverSwitch_Context *ctx) { - Uint8 *pLeftStickCal; - Uint8 *pRightStickCal; + Uint8 *pLeftStickCal = NULL; + Uint8 *pRightStickCal = NULL; size_t stick, axis; SwitchSubcommandInputPacket_t *user_reply = NULL; SwitchSubcommandInputPacket_t *factory_reply = NULL; @@ -984,6 +984,12 @@ static bool LoadStickCalibration(SDL_DriverSwitch_Context *ctx) } } + // If we still don't have calibration data, return false + if (pLeftStickCal == NULL || pRightStickCal == NULL) + { + return false; + } + /* Stick calibration values are 12-bits each and are packed by bit * For whatever reason the fields are in a different order for each stick * Left: X-Max, Y-Max, X-Center, Y-Center, X-Min, Y-Min