[Commits] SDL: Fixed bug 4005 - Android, SDL_IsGameController() crashes is...

libsdl.org revision control commits-owner at libsdl.org
Tue Dec 19 10:48:33 PST 2017


details:   https://hg.libsdl.org/SDL/rev/c2f3e4187c9d
changeset: 11781:c2f3e4187c9d
user:      Sam Lantinga <slouken at libsdl.org>
date:      Tue Dec 19 10:48:29 2017 -0800
description:
Fixed bug 4005 - Android, SDL_IsGameController() crashes is index is out of range

Sylvain

On Android, if you give an invalid index to SDL_IsGameController(), it will crash in SDL_SYS_IsDPAD_DeviceIndex().

diffstat:

 src/joystick/SDL_gamecontroller.c |  12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

diffs (34 lines):

diff -r 874fb85ef7b7 -r c2f3e4187c9d src/joystick/SDL_gamecontroller.c
--- a/src/joystick/SDL_gamecontroller.c	Sat Dec 16 10:40:47 2017 -0800
+++ b/src/joystick/SDL_gamecontroller.c	Tue Dec 19 10:48:29 2017 -0800
@@ -911,6 +911,13 @@
     ControllerMapping_t *mapping;
 
     SDL_LockJoysticks();
+
+    if ((device_index < 0) || (device_index >= SDL_NumJoysticks())) {
+        SDL_SetError("There are %d joysticks available", SDL_NumJoysticks());
+        SDL_UnlockJoysticks();
+        return (NULL);
+    }
+
     name = SDL_JoystickNameForIndex(device_index);
     guid = SDL_JoystickGetDeviceGUID(device_index);
     mapping = SDL_PrivateGetControllerMappingForNameAndGUID(name, guid);
@@ -1353,13 +1360,14 @@
     SDL_GameController *gamecontrollerlist;
     ControllerMapping_t *pSupportedController = NULL;
 
+    SDL_LockJoysticks();
+
     if ((device_index < 0) || (device_index >= SDL_NumJoysticks())) {
         SDL_SetError("There are %d joysticks available", SDL_NumJoysticks());
+        SDL_UnlockJoysticks();
         return (NULL);
     }
 
-    SDL_LockJoysticks();
-
     gamecontrollerlist = SDL_gamecontrollers;
     /* If the controller is already open, return it */
     while (gamecontrollerlist) {


More information about the commits mailing list