Fixed crash if joystick functions are passed a NULL joystick

main
Sam Lantinga 2023-12-27 11:25:54 -08:00
parent 4ce935b910
commit 0dfdf1f3f2
1 changed files with 29 additions and 17 deletions

View File

@ -1521,6 +1521,9 @@ const char *SDL_GetJoystickName(SDL_Joystick *joystick)
const SDL_SteamVirtualGamepadInfo *info;
SDL_LockJoysticks();
{
CHECK_JOYSTICK_MAGIC(joystick, NULL);
info = SDL_GetJoystickInstanceVirtualGamepadInfo(joystick->instance_id);
if (info) {
retval = info->name;
@ -1529,6 +1532,7 @@ const char *SDL_GetJoystickName(SDL_Joystick *joystick)
retval = joystick->name;
}
}
SDL_UnlockJoysticks();
/* FIXME: Really we should reference count this name so it doesn't go away after unlock */
@ -3247,6 +3251,9 @@ Uint16 SDL_GetJoystickVendor(SDL_Joystick *joystick)
const SDL_SteamVirtualGamepadInfo *info;
SDL_LockJoysticks();
{
CHECK_JOYSTICK_MAGIC(joystick, 0);
info = SDL_GetJoystickInstanceVirtualGamepadInfo(joystick->instance_id);
if (info) {
vendor = info->vendor_id;
@ -3255,6 +3262,7 @@ Uint16 SDL_GetJoystickVendor(SDL_Joystick *joystick)
SDL_GetJoystickGUIDInfo(guid, &vendor, NULL, NULL, NULL);
}
}
SDL_UnlockJoysticks();
return vendor;
@ -3266,6 +3274,9 @@ Uint16 SDL_GetJoystickProduct(SDL_Joystick *joystick)
const SDL_SteamVirtualGamepadInfo *info;
SDL_LockJoysticks();
{
CHECK_JOYSTICK_MAGIC(joystick, 0);
info = SDL_GetJoystickInstanceVirtualGamepadInfo(joystick->instance_id);
if (info) {
product = info->product_id;
@ -3274,6 +3285,7 @@ Uint16 SDL_GetJoystickProduct(SDL_Joystick *joystick)
SDL_GetJoystickGUIDInfo(guid, NULL, &product, NULL, NULL);
}
}
SDL_UnlockJoysticks();
return product;