Skip to content

Commit

Permalink
Fixed SDL_GameControllerMappingForGUID() crashing if no more memory a…
Browse files Browse the repository at this point in the history
…vailable.

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).
  • Loading branch information
philippwiesemann committed Oct 26, 2014
1 parent 30d6cec commit 33a2b58
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/joystick/SDL_gamecontroller.c
Expand Up @@ -735,6 +735,10 @@ SDL_GameControllerMappingForGUID(SDL_JoystickGUID guid)
/* allocate enough memory for GUID + ',' + name + ',' + mapping + \0 */
needed = SDL_strlen(pchGUID) + 1 + SDL_strlen(mapping->name) + 1 + SDL_strlen(mapping->mapping) + 1;
pMappingString = SDL_malloc(needed);
if (!pMappingString) {
SDL_OutOfMemory();
return NULL;
}
SDL_snprintf(pMappingString, needed, "%s,%s,%s", pchGUID, mapping->name, mapping->mapping);
}
return pMappingString;
Expand Down

0 comments on commit 33a2b58

Please sign in to comment.