From 23c39a2e448ec711708de17fc9282faa7c379a55 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 12 Dec 2019 19:14:37 -0800 Subject: [PATCH] Strip trailing whitespace on controller manufacturer identification --- src/joystick/darwin/SDL_sysjoystick.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/joystick/darwin/SDL_sysjoystick.c b/src/joystick/darwin/SDL_sysjoystick.c index c3ad609bc..5c4dafc93 100644 --- a/src/joystick/darwin/SDL_sysjoystick.c +++ b/src/joystick/darwin/SDL_sysjoystick.c @@ -405,6 +405,7 @@ GetDeviceInfo(IOHIDDeviceRef hidDevice, recDevice *pDevice) CFTypeRef refCF = NULL; CFArrayRef array = NULL; Uint16 *guid16 = (Uint16 *)pDevice->guid.data; + int i; /* get usage page and usage */ refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDPrimaryUsagePageKey)); @@ -456,6 +457,13 @@ GetDeviceInfo(IOHIDDeviceRef hidDevice, recDevice *pDevice) if ((!refCF) || (!CFStringGetCString(refCF, product_string, sizeof(product_string), kCFStringEncodingUTF8))) { SDL_strlcpy(product_string, "Unidentified joystick", sizeof(product_string)); } + for (i = SDL_strlen(manufacturer_string) - 1; i > 0; --i) { + if (SDL_isspace(manufacturer_string[i])) { + manufacturer_string[i] = '\0'; + } else { + break; + } + } if (SDL_strncasecmp(manufacturer_string, product_string, SDL_strlen(manufacturer_string)) == 0) { SDL_strlcpy(pDevice->product, product_string, sizeof(pDevice->product)); } else {