Browse Source

Gracefully handle negative indexes in love.joystick (bug #172)

Bart van Strien 14 years ago
parent
commit
98406370eb
1 changed files with 3 additions and 5 deletions
  1. 3 5
      src/modules/joystick/sdl/Joystick.cpp

+ 3 - 5
src/modules/joystick/sdl/Joystick.cpp

@@ -68,15 +68,13 @@ namespace sdl
 
 
 	bool Joystick::checkIndex(int index)
 	bool Joystick::checkIndex(int index)
 	{
 	{
-		if(index < getNumJoysticks())
-			return true;
-		else
-			return false;
+		return index >= 0 && index < getNumJoysticks();
 	}
 	}
 
 
 	int Joystick::getNumJoysticks()
 	int Joystick::getNumJoysticks()
 	{
 	{
-		return SDL_NumJoysticks();
+		int num = SDL_NumJoysticks();
+		return num < 0 ? 0 : num;
 	}
 	}
 
 
 	const char * Joystick::getName(int index)
 	const char * Joystick::getName(int index)