Fixed SDL_GameControllerMappingForGUID() crashing if no more memory available.
authorPhilipp Wiesemann <philipp.wiesemann@arcor.de>
Sun, 26 Oct 2014 23:22:53 +0100
changeset 9197 90bb83c49dea
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
--- a/src/joystick/SDL_gamecontroller.c	Sun Oct 26 17:53:16 2014 +0100
+++ b/src/joystick/SDL_gamecontroller.c	Sun Oct 26 23:22:53 2014 +0100
@@ -735,6 +735,10 @@
         /* 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;