Fixed crash trying to get the GUID of an invalid joystick index
authorSam Lantinga <slouken@libsdl.org>
Thu, 06 Jun 2013 18:20:06 -0700
changeset 7294 0923de98a63a
parent 7293 341d22fe9044
child 7295 737cc5bad795
Fixed crash trying to get the GUID of an invalid joystick index
src/joystick/SDL_joystick.c
--- a/src/joystick/SDL_joystick.c	Thu Jun 06 17:59:01 2013 -0700
+++ b/src/joystick/SDL_joystick.c	Thu Jun 06 18:20:06 2013 -0700
@@ -729,6 +729,12 @@
 /* return the guid for this index */
 SDL_JoystickGUID SDL_JoystickGetDeviceGUID(int device_index)
 {
+    if ((device_index < 0) || (device_index >= SDL_NumJoysticks())) {
+        SDL_JoystickGUID emptyGUID;
+        SDL_SetError("There are %d joysticks available", SDL_NumJoysticks());
+        SDL_zero( emptyGUID );
+        return emptyGUID;
+    }
     return SDL_SYS_JoystickGetDeviceGUID( device_index );
 }