Skip to content

Commit

Permalink
Fix crash when joystick name unavailable on OS X
Browse files Browse the repository at this point in the history
Fixes issue glfw#694
  • Loading branch information
aaronmjacobs committed Feb 8, 2016
1 parent f51cf81 commit 87293db
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/cocoa_joystick.m
Expand Up @@ -29,6 +29,7 @@

#include <unistd.h>
#include <ctype.h>
#include <string.h>

#include <mach/mach.h>
#include <mach/mach_error.h>
Expand Down Expand Up @@ -287,11 +288,17 @@ static void matchCallback(void* context,

CFStringRef name = IOHIDDeviceGetProperty(deviceRef,
CFSTR(kIOHIDProductKey));
CFStringGetCString(name,
joystick->name,
sizeof(joystick->name),
kCFStringEncodingUTF8);

if (name)
{
CFStringGetCString(name,
joystick->name,
sizeof(joystick->name),
kCFStringEncodingUTF8);
}
else
{
strncpy(joystick->name, "Unknown", sizeof(joystick->name));
}
joystick->axisElements = CFArrayCreateMutable(NULL, 0, NULL);
joystick->buttonElements = CFArrayCreateMutable(NULL, 0, NULL);
joystick->hatElements = CFArrayCreateMutable(NULL, 0, NULL);
Expand Down

0 comments on commit 87293db

Please sign in to comment.