Fixes 2356, [Android] SDL_JoystickGetAttached does not function
authorGabriel Jacobo <gabomdq@gmail.com>
Tue, 21 Jan 2014 18:20:12 -0300
changeset 8119df0bf33be2ca
parent 8118 f0b6338dc866
child 8120 c858be546e5a
Fixes 2356, [Android] SDL_JoystickGetAttached does not function

Also fix a potential NULL pointer access in android/SDL_SYS_JoystickGetGUID
src/joystick/android/SDL_sysjoystick.c
     1.1 --- a/src/joystick/android/SDL_sysjoystick.c	Tue Jan 21 13:58:15 2014 -0500
     1.2 +++ b/src/joystick/android/SDL_sysjoystick.c	Tue Jan 21 18:20:12 2014 -0300
     1.3 @@ -284,6 +284,10 @@
     1.4      }
     1.5  
     1.6      const int retval = item->device_instance;
     1.7 +    if (item->joystick) {
     1.8 +        item->joystick->hwdata = NULL;
     1.9 +    }
    1.10 +        
    1.11      if (prev != NULL) {
    1.12          prev->next = item->next;
    1.13      } else {
    1.14 @@ -507,7 +511,14 @@
    1.15  
    1.16  SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
    1.17  {
    1.18 -    return ((SDL_joylist_item*)joystick->hwdata)->guid;
    1.19 +    SDL_JoystickGUID guid;
    1.20 +    
    1.21 +    if (joystick->hwdata != NULL) {
    1.22 +        return ((SDL_joylist_item*)joystick->hwdata)->guid;
    1.23 +    }
    1.24 +    
    1.25 +    SDL_zero(guid);
    1.26 +    return guid;
    1.27  }
    1.28  
    1.29  #endif /* SDL_JOYSTICK_ANDROID */