Navigation Menu

Skip to content

Commit

Permalink
Fixed bug 4005 - Android, SDL_IsGameController() crashes is index is …
Browse files Browse the repository at this point in the history
…out of range

Sylvain

On Android, if you give an invalid index to SDL_IsGameController(), it will crash in SDL_SYS_IsDPAD_DeviceIndex().
  • Loading branch information
slouken committed Dec 19, 2017
1 parent e5cfa24 commit fee2469
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/joystick/SDL_gamecontroller.c
Expand Up @@ -911,6 +911,13 @@ static ControllerMapping_t *SDL_PrivateGetControllerMapping(int device_index)
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);
Expand Down Expand Up @@ -1353,13 +1360,14 @@ SDL_GameControllerOpen(int device_index)
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) {
Expand Down

0 comments on commit fee2469

Please sign in to comment.