Commits

Bart van Strien committed 40f98a8

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

  • Participants
  • Parent commits 150b94a

Comments (0)

Files changed (1)

File src/modules/joystick/sdl/Joystick.cpp

 
 	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)