Commit 491fba1d06a4810645092b2559b9cc94abeb23bb

Sam Lantinga 2023-06-24T15:38:38

SDL_FindFreePlayerIndex() will always return the next available player index Fixes https://github.com/libsdl-org/SDL/issues/7868 (cherry picked from commit 87e916dd214866af9cfd67eb4618918bc8b0f1b4) (cherry picked from commit 38619bb28db83bc5844d13d99b3072496adcd498)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c
index 5e46bc1..12965f9 100644
--- a/src/joystick/SDL_joystick.c
+++ b/src/joystick/SDL_joystick.c
@@ -221,10 +221,10 @@ static int SDL_FindFreePlayerIndex()
 
     for (player_index = 0; player_index < SDL_joystick_player_count; ++player_index) {
         if (SDL_joystick_players[player_index] == -1) {
-            return player_index;
+            break;
         }
     }
-    return -1;
+    return player_index;
 }
 
 static int SDL_GetPlayerIndexForJoystickID(SDL_JoystickID instance_id)