Commit b131e74be4923cbb2f8dd271f10c2ef228efb593

Gabriel Jacobo 2014-01-21T18:20:12

Fixes 2356, [Android] SDL_JoystickGetAttached does not function Also fix a potential NULL pointer access in android/SDL_SYS_JoystickGetGUID

diff --git a/src/joystick/android/SDL_sysjoystick.c b/src/joystick/android/SDL_sysjoystick.c
index 0772eae..229a48d 100644
--- a/src/joystick/android/SDL_sysjoystick.c
+++ b/src/joystick/android/SDL_sysjoystick.c
@@ -284,6 +284,10 @@ Android_RemoveJoystick(int device_id)
     }
 
     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_JoystickGetDeviceGUID( int device_index )
 
 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 */