From 98406370eb9ec38f1b34e3b0260d935ed85d7383 Mon Sep 17 00:00:00 2001 From: Bart van Strien Date: Mon, 17 Jan 2011 11:04:02 +0100 Subject: [PATCH] Gracefully handle negative indexes in love.joystick (bug #172) --- src/modules/joystick/sdl/Joystick.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/modules/joystick/sdl/Joystick.cpp b/src/modules/joystick/sdl/Joystick.cpp index 7983bb1d7..5c896147a 100644 --- a/src/modules/joystick/sdl/Joystick.cpp +++ b/src/modules/joystick/sdl/Joystick.cpp @@ -68,15 +68,13 @@ namespace sdl bool Joystick::checkIndex(int index) { - if(index < getNumJoysticks()) - return true; - else - return false; + return index >= 0 && index < getNumJoysticks(); } int Joystick::getNumJoysticks() { - return SDL_NumJoysticks(); + int num = SDL_NumJoysticks(); + return num < 0 ? 0 : num; } const char * Joystick::getName(int index)