Преглед изворни кода

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

Bart van Strien пре 14 година
родитељ
комит
98406370eb
1 измењених фајлова са 3 додато и 5 уклоњено
  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)
 	{
-		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)