From b18f547d8fd3da129bea7f8e1a0fe10d35f0784d Mon Sep 17 00:00:00 2001 From: MikiZX1 <161243635+MikiZX1@users.noreply.github.com> Date: Tue, 18 Nov 2025 16:19:07 +0100 Subject: [PATCH] Update rcore_desktop_sdl.c, fix crash when strncpy tries to copy using NULL pointer (#5359) When SDL_GameControllerNameForIndex returns null, the app crashes. This was addressed earlier in PR#4859 though the fix submitted on PR #4859 was only fixing the crashing and not addressing the root cause. --- src/platforms/rcore_desktop_sdl.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/platforms/rcore_desktop_sdl.c b/src/platforms/rcore_desktop_sdl.c index cf11037cb..e9686912b 100644 --- a/src/platforms/rcore_desktop_sdl.c +++ b/src/platforms/rcore_desktop_sdl.c @@ -1723,7 +1723,10 @@ void PollInputEvents(void) CORE.Input.Gamepad.axisState[nextAvailableSlot][GAMEPAD_AXIS_LEFT_TRIGGER] = -1.0f; CORE.Input.Gamepad.axisState[nextAvailableSlot][GAMEPAD_AXIS_RIGHT_TRIGGER] = -1.0f; memset(CORE.Input.Gamepad.name[nextAvailableSlot], 0, MAX_GAMEPAD_NAME_LENGTH); - strncpy(CORE.Input.Gamepad.name[nextAvailableSlot], SDL_GameControllerNameForIndex(nextAvailableSlot), MAX_GAMEPAD_NAME_LENGTH - 1); + if (SDL_GameControllerNameForIndex(nextAvailableSlot)) + strncpy(CORE.Input.Gamepad.name[nextAvailableSlot], SDL_GameControllerNameForIndex(nextAvailableSlot), MAX_GAMEPAD_NAME_LENGTH - 1); + else + strncpy(CORE.Input.Gamepad.name[nextAvailableSlot], "Noname", 6); } else {