Fixes 2356, [Android] SDL_JoystickGetAttached does not function
authorGabriel Jacobo <gabomdq@gmail.com>
Tue, 21 Jan 2014 18:20:12 -0300
changeset 8119 df0bf33be2ca
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
--- a/src/joystick/android/SDL_sysjoystick.c	Tue Jan 21 13:58:15 2014 -0500
+++ b/src/joystick/android/SDL_sysjoystick.c	Tue Jan 21 18:20:12 2014 -0300
@@ -284,6 +284,10 @@
     }
 
     const int retval = item->device_instance;
+    if (item->joystick) {
+        item->joystick->hwdata = NULL;
+    }
+        
     if (prev != NULL) {
         prev->next = item->next;
     } else {
@@ -507,7 +511,14 @@
 
 SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
 {
-    return ((SDL_joylist_item*)joystick->hwdata)->guid;
+    SDL_JoystickGUID guid;
+    
+    if (joystick->hwdata != NULL) {
+        return ((SDL_joylist_item*)joystick->hwdata)->guid;
+    }
+    
+    SDL_zero(guid);
+    return guid;
 }
 
 #endif /* SDL_JOYSTICK_ANDROID */