mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-05-12 14:54:35 +02:00
Fixed a crash if we get a HID device with no path
This can happen on Linux if udev_device_get_devnode() fails.
(cherry picked from commit bb4eedd67d)
This commit is contained in:
@@ -897,14 +897,19 @@ static SDL_HIDAPI_Device *HIDAPI_AddDevice(const struct SDL_hid_device_info *inf
|
||||
for (curr = SDL_HIDAPI_devices, last = NULL; curr; last = curr, curr = curr->next) {
|
||||
}
|
||||
|
||||
char *path = SDL_strdup(info->path);
|
||||
if (!path) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
device = (SDL_HIDAPI_Device *)SDL_calloc(1, sizeof(*device));
|
||||
if (!device) {
|
||||
SDL_free(path);
|
||||
return NULL;
|
||||
}
|
||||
SDL_SetObjectValid(device, SDL_OBJECT_TYPE_HIDAPI_JOYSTICK, true);
|
||||
if (info->path) {
|
||||
device->path = SDL_strdup(info->path);
|
||||
}
|
||||
device->path = path;
|
||||
device->seen = true;
|
||||
device->vendor_id = info->vendor_id;
|
||||
device->product_id = info->product_id;
|
||||
@@ -1136,6 +1141,11 @@ static void HIDAPI_UpdateDeviceList(void)
|
||||
devs = SDL_hid_enumerate(0, 0);
|
||||
if (devs) {
|
||||
for (info = devs; info; info = info->next) {
|
||||
if (!info->path) {
|
||||
// We can't open this, ignore it
|
||||
continue;
|
||||
}
|
||||
|
||||
device = HIDAPI_GetJoystickByInfo(info->path, info->vendor_id, info->product_id);
|
||||
if (device) {
|
||||
device->seen = true;
|
||||
|
||||
Reference in New Issue
Block a user