SDL: SDL_GameControllerSetPlayerIndex(gamecontroller, -1) means turn off the player LED if possible

From df537a7c0e30124c7602f6dd8e5afcb10afba36f Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Tue, 9 Aug 2022 00:18:19 -0700
Subject: [PATCH] SDL_GameControllerSetPlayerIndex(gamecontroller, -1) means
 turn off the player LED if possible

---
 src/joystick/hidapi/SDL_hidapi_switch.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/joystick/hidapi/SDL_hidapi_switch.c b/src/joystick/hidapi/SDL_hidapi_switch.c
index e8680b4d517..99e3c3755a6 100644
--- a/src/joystick/hidapi/SDL_hidapi_switch.c
+++ b/src/joystick/hidapi/SDL_hidapi_switch.c
@@ -848,9 +848,11 @@ static void SDLCALL SDL_HomeLEDHintChanged(void *userdata, const char *name, con
 static void UpdateSlotLED(SDL_DriverSwitch_Context *ctx)
 {
     if (!ctx->m_bInputOnly) {
-        Uint8 slot = (ctx->m_nPlayerIndex % 4);
-        Uint8 led_data = ctx->m_bPlayerLights ? (1 << slot) : 0;
-
+        Uint8 led_data = 0;
+        
+        if (ctx->m_bPlayerLights && ctx->m_nPlayerIndex >= 0) {
+            led_data = (1 << (ctx->m_nPlayerIndex % 4));
+        }
         WriteSubcommand(ctx, k_eSwitchSubcommandIDs_SetPlayerLights, &led_data, sizeof(led_data), NULL);
     }
 }