Browse Source

Fixed crash if a device doesn't have a USB product or manufacturer string

This happens with the Razer Huntsman V3 Pro Tenkeyless keyboard
Sam Lantinga 4 months ago
parent
commit
235e5c6a6c
1 changed files with 8 additions and 2 deletions
  1. 8 2
      src/joystick/hidapi/SDL_hidapijoystick.c

+ 8 - 2
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();