Fix crash when joystick name unavailable on OS X

Fixes issue #694
This commit is contained in:
Aaron Jacobs 2016-02-08 11:21:48 -08:00
parent f51cf81148
commit 87293db93b

View File

@ -29,6 +29,7 @@
#include <unistd.h> #include <unistd.h>
#include <ctype.h> #include <ctype.h>
#include <string.h>
#include <mach/mach.h> #include <mach/mach.h>
#include <mach/mach_error.h> #include <mach/mach_error.h>
@ -287,11 +288,17 @@ static void matchCallback(void* context,
CFStringRef name = IOHIDDeviceGetProperty(deviceRef, CFStringRef name = IOHIDDeviceGetProperty(deviceRef,
CFSTR(kIOHIDProductKey)); CFSTR(kIOHIDProductKey));
CFStringGetCString(name, if (name)
joystick->name, {
sizeof(joystick->name), CFStringGetCString(name,
kCFStringEncodingUTF8); joystick->name,
sizeof(joystick->name),
kCFStringEncodingUTF8);
}
else
{
strncpy(joystick->name, "Unknown", sizeof(joystick->name));
}
joystick->axisElements = CFArrayCreateMutable(NULL, 0, NULL); joystick->axisElements = CFArrayCreateMutable(NULL, 0, NULL);
joystick->buttonElements = CFArrayCreateMutable(NULL, 0, NULL); joystick->buttonElements = CFArrayCreateMutable(NULL, 0, NULL);
joystick->hatElements = CFArrayCreateMutable(NULL, 0, NULL); joystick->hatElements = CFArrayCreateMutable(NULL, 0, NULL);