MacOS: Don't crash if no elements are returned by IOHIDDeviceCopyMatchingElements

Fixes #797
This commit is contained in:
LD 2019-11-28 23:37:33 +01:00 committed by rdb
parent f72c72b36a
commit 791be4766a

View File

@ -114,12 +114,14 @@ IOKitInputDevice(IOHIDDeviceRef device) :
}
CFArrayRef elements = IOHIDDeviceCopyMatchingElements(device, nullptr, 0);
CFIndex count = CFArrayGetCount(elements);
for (CFIndex i = 0; i < count; ++i) {
IOHIDElementRef element = (IOHIDElementRef)CFArrayGetValueAtIndex(elements, i);
parse_element(element);
if (elements) {
CFIndex count = CFArrayGetCount(elements);
for (CFIndex i = 0; i < count; ++i) {
IOHIDElementRef element = (IOHIDElementRef)CFArrayGetValueAtIndex(elements, i);
parse_element(element);
}
CFRelease(elements);
}
CFRelease(elements);
if (_hat_element != nullptr) {
_hat_left_button = (int)_buttons.size();