From 235e5c6a6ca7eccc03d4898c4c3a393294c98721 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 5 Dec 2024 10:42:02 -0800 Subject: [PATCH] Fixed crash if a device doesn't have a USB product or manufacturer string This happens with the Razer Huntsman V3 Pro Tenkeyless keyboard --- src/joystick/hidapi/SDL_hidapijoystick.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/joystick/hidapi/SDL_hidapijoystick.c b/src/joystick/hidapi/SDL_hidapijoystick.c index c3ec20645d..1b348f1e0e 100644 --- a/src/joystick/hidapi/SDL_hidapijoystick.c +++ b/src/joystick/hidapi/SDL_hidapijoystick.c @@ -1293,7 +1293,10 @@ char *HIDAPI_GetDeviceProductName(Uint16 vendor_id, Uint16 product_id) SDL_LockJoysticks(); for (device = SDL_HIDAPI_devices; device; device = device->next) { if (vendor_id == device->vendor_id && product_id == device->product_id) { - name = SDL_strdup(device->product_string); + if (device->product_string) { + name = SDL_strdup(device->product_string); + } + break; } } SDL_UnlockJoysticks(); @@ -1309,7 +1312,10 @@ char *HIDAPI_GetDeviceManufacturerName(Uint16 vendor_id, Uint16 product_id) SDL_LockJoysticks(); for (device = SDL_HIDAPI_devices; device; device = device->next) { if (vendor_id == device->vendor_id && product_id == device->product_id) { - name = SDL_strdup(device->manufacturer_string); + if (device->manufacturer_string) { + name = SDL_strdup(device->manufacturer_string); + } + break; } } SDL_UnlockJoysticks();