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.
This commit is contained in:
mitchellcairns 2025-06-22 19:17:02 -07:00 committed by GitHub
parent ff9c4b2a70
commit a26f8fbd6c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 2 deletions

View File

@ -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