Quellcode durchsuchen

Make sure the mapping string doesn't have extraneous whitespace

If that whitespace is extra newlines in the mapping hint, we would create extra empty mapping strings
Sam Lantinga vor 2 Jahren
Ursprung
Commit
7aec9ad4a6
1 geänderte Dateien mit 20 neuen und 1 gelöschten Zeilen
  1. 20 1
      src/joystick/SDL_gamepad.c

+ 20 - 1
src/joystick/SDL_gamepad.c

@@ -1401,6 +1401,8 @@ static char *SDL_PrivateGetGamepadNameFromMappingString(const char *pMapping)
 static char *SDL_PrivateGetGamepadMappingFromMappingString(const char *pMapping)
 static char *SDL_PrivateGetGamepadMappingFromMappingString(const char *pMapping)
 {
 {
     const char *pFirstComma, *pSecondComma;
     const char *pFirstComma, *pSecondComma;
+    char *result;
+    size_t length;
 
 
     pFirstComma = SDL_strchr(pMapping, ',');
     pFirstComma = SDL_strchr(pMapping, ',');
     if (pFirstComma == NULL) {
     if (pFirstComma == NULL) {
@@ -1412,7 +1414,24 @@ static char *SDL_PrivateGetGamepadMappingFromMappingString(const char *pMapping)
         return NULL;
         return NULL;
     }
     }
 
 
-    return SDL_strdup(pSecondComma + 1); /* mapping is everything after the 3rd comma */
+    /* Skip whitespace */
+    while (SDL_isspace(pSecondComma[1])) {
+        ++pSecondComma;
+    }
+    if (pSecondComma[1] == '\0') {
+        return NULL;
+    }
+
+    result = SDL_strdup(pSecondComma + 1); /* mapping is everything after the 3rd comma */
+
+    /* Trim whitespace */
+    length = SDL_strlen(result);
+    while (SDL_isspace(result[length - 1])) {
+        --length;
+    }
+    result[length] = '\0';
+
+    return result;
 }
 }
 
 
 /*
 /*