From 55882e43c4442e9a1a7a7df9cc83849c6e5f232b Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 9 Aug 2022 00:19:02 -0700 Subject: [PATCH] Fixed invalid read when SDL_GameControllerSetPlayerIndex() is passed a negative player_index --- src/joystick/SDL_joystick.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c index 0d778a739e..94217cce91 100644 --- a/src/joystick/SDL_joystick.c +++ b/src/joystick/SDL_joystick.c @@ -186,7 +186,7 @@ SDL_SetJoystickIDForPlayerIndex(int player_index, SDL_JoystickID instance_id) SDL_joystick_players = new_players; SDL_memset(&SDL_joystick_players[SDL_joystick_player_count], 0xFF, (player_index - SDL_joystick_player_count + 1) * sizeof(SDL_joystick_players[0])); SDL_joystick_player_count = player_index + 1; - } else if (SDL_joystick_players[player_index] == instance_id) { + } else if (player_index >= 0 && SDL_joystick_players[player_index] == instance_id) { /* Joystick is already assigned the requested player index */ return SDL_TRUE; }