Strip trailing whitespace on controller manufacturer identification
authorSam Lantinga <slouken@libsdl.org>
Thu, 12 Dec 2019 19:14:37 -0800
changeset 1333928292d16d893
parent 13338 1caca966b0c6
child 13340 37662e38b645
Strip trailing whitespace on controller manufacturer identification
src/joystick/darwin/SDL_sysjoystick.c
     1.1 --- a/src/joystick/darwin/SDL_sysjoystick.c	Thu Dec 12 14:26:34 2019 -0800
     1.2 +++ b/src/joystick/darwin/SDL_sysjoystick.c	Thu Dec 12 19:14:37 2019 -0800
     1.3 @@ -405,6 +405,7 @@
     1.4      CFTypeRef refCF = NULL;
     1.5      CFArrayRef array = NULL;
     1.6      Uint16 *guid16 = (Uint16 *)pDevice->guid.data;
     1.7 +    int i;
     1.8  
     1.9      /* get usage page and usage */
    1.10      refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDPrimaryUsagePageKey));
    1.11 @@ -456,6 +457,13 @@
    1.12          if ((!refCF) || (!CFStringGetCString(refCF, product_string, sizeof(product_string), kCFStringEncodingUTF8))) {
    1.13              SDL_strlcpy(product_string, "Unidentified joystick", sizeof(product_string));
    1.14          }
    1.15 +        for (i = SDL_strlen(manufacturer_string) - 1; i > 0; --i) {
    1.16 +            if (SDL_isspace(manufacturer_string[i])) {
    1.17 +                manufacturer_string[i] = '\0';
    1.18 +            } else {
    1.19 +                break;
    1.20 +            }
    1.21 +        }
    1.22          if (SDL_strncasecmp(manufacturer_string, product_string, SDL_strlen(manufacturer_string)) == 0) {
    1.23              SDL_strlcpy(pDevice->product, product_string, sizeof(pDevice->product));
    1.24          } else {