From c6b03094a34836211d448319ef7556d6cfae4b80 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 6 Jun 2013 18:20:06 -0700 Subject: [PATCH] Fixed crash trying to get the GUID of an invalid joystick index --- src/joystick/SDL_joystick.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c index 0342e6ba9..a4417c6cb 100644 --- a/src/joystick/SDL_joystick.c +++ b/src/joystick/SDL_joystick.c @@ -729,6 +729,12 @@ SDL_PrivateJoystickNeedsPolling() /* 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 ); }