Check bounds in SDL_IsGameController. Switch two functions to SDL_bool.
authorJørgen P. Tjernø <jorgen@valvesoftware.com>
Tue, 12 Feb 2013 17:07:21 -0800
changeset 6871bd681c870ccf
parent 6870 31dee5110b4d
child 6872 2f4c95464651
Check bounds in SDL_IsGameController. Switch two functions to SDL_bool.

Switches SDL_GameControllerGetAttached and SDL_IsGameController to
return SDL_bool, instead of int.
include/SDL_gamecontroller.h
src/joystick/SDL_gamecontroller.c
     1.1 --- a/include/SDL_gamecontroller.h	Tue Feb 12 16:17:24 2013 -0800
     1.2 +++ b/include/SDL_gamecontroller.h	Tue Feb 12 17:07:21 2013 -0800
     1.3 @@ -113,7 +113,7 @@
     1.4   *  Is the joystick on this index supported by the game controller interface?
     1.5   *		returns 1 if supported, 0 otherwise.
     1.6   */
     1.7 -extern DECLSPEC int SDLCALL SDL_IsGameController(int joystick_index);
     1.8 +extern DECLSPEC SDL_bool SDLCALL SDL_IsGameController(int joystick_index);
     1.9  
    1.10  
    1.11  /**
    1.12 @@ -141,7 +141,7 @@
    1.13  /**
    1.14   *  Returns 1 if the controller has been opened and currently connected, or 0 if it has not.
    1.15   */
    1.16 -extern DECLSPEC int SDLCALL SDL_GameControllerGetAttached(SDL_GameController * gamecontroller);
    1.17 +extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerGetAttached(SDL_GameController * gamecontroller);
    1.18  
    1.19  /**
    1.20   *  Get the underlying joystick object used by a controller
     2.1 --- a/src/joystick/SDL_gamecontroller.c	Tue Feb 12 16:17:24 2013 -0800
     2.2 +++ b/src/joystick/SDL_gamecontroller.c	Tue Feb 12 17:07:21 2013 -0800
     2.3 @@ -265,6 +265,10 @@
     2.4   */
     2.5  ControllerMapping_t *SDL_PrivateGetControllerMapping(int device_index)
     2.6  {
     2.7 +    if ( (device_index < 0) || (device_index >= SDL_NumJoysticks()) ) {
     2.8 +        return NULL;
     2.9 +    }
    2.10 +
    2.11  #ifdef SDL_JOYSTICK_DINPUT
    2.12  	if ( SDL_SYS_IsXInputDeviceIndex(device_index) && s_pXInputMapping )
    2.13  	{
    2.14 @@ -741,14 +745,16 @@
    2.15  /*
    2.16   * Return 1 if the joystick at this device index is a supported controller
    2.17   */
    2.18 -int SDL_IsGameController(int device_index)
    2.19 +SDL_bool
    2.20 +SDL_IsGameController(int device_index)
    2.21  {
    2.22  	ControllerMapping_t *pSupportedController =  SDL_PrivateGetControllerMapping(device_index);
    2.23  	if ( pSupportedController )
    2.24  	{
    2.25 -		return 1;
    2.26 +		return SDL_TRUE;
    2.27  	}
    2.28 -	return 0;
    2.29 +
    2.30 +	return SDL_FALSE;
    2.31  }
    2.32  
    2.33  /*
    2.34 @@ -881,11 +887,11 @@
    2.35   * Return if the joystick in question is currently attached to the system,
    2.36   *  \return 0 if not plugged in, 1 if still present.
    2.37   */
    2.38 -int
    2.39 +SDL_bool
    2.40  SDL_GameControllerGetAttached( SDL_GameController * gamecontroller )
    2.41  {
    2.42  	if ( !gamecontroller )
    2.43 -		return 0;
    2.44 +		return SDL_FALSE;
    2.45  
    2.46  	return SDL_JoystickGetAttached(gamecontroller->joystick);
    2.47  }