Fixed SDL_GameControllerMappingForGUID() crashing if no more memory available.
authorPhilipp Wiesemann <philipp.wiesemann@arcor.de>
Sun, 26 Oct 2014 23:22:53 +0100
changeset 919790bb83c49dea
parent 9196 3c3a84b56da0
child 9198 7260f8242948
Fixed SDL_GameControllerMappingForGUID() crashing if no more memory available.

The return value of SDL_malloc() was not checked and NULL therefore not handled.
NULL returned by SDL_GameControllerMapping()/SDL_GameControllerMappingForGUID()
now either means "no mapping" (as before) or "no memory" (just crashed before).
src/joystick/SDL_gamecontroller.c
     1.1 --- a/src/joystick/SDL_gamecontroller.c	Sun Oct 26 17:53:16 2014 +0100
     1.2 +++ b/src/joystick/SDL_gamecontroller.c	Sun Oct 26 23:22:53 2014 +0100
     1.3 @@ -735,6 +735,10 @@
     1.4          /* allocate enough memory for GUID + ',' + name + ',' + mapping + \0 */
     1.5          needed = SDL_strlen(pchGUID) + 1 + SDL_strlen(mapping->name) + 1 + SDL_strlen(mapping->mapping) + 1;
     1.6          pMappingString = SDL_malloc(needed);
     1.7 +        if (!pMappingString) {
     1.8 +            SDL_OutOfMemory();
     1.9 +            return NULL;
    1.10 +        }
    1.11          SDL_snprintf(pMappingString, needed, "%s,%s,%s", pchGUID, mapping->name, mapping->mapping);
    1.12      }
    1.13      return pMappingString;