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.
This commit is contained in:
MikiZX1 2025-11-18 16:19:07 +01:00 committed by GitHub
parent be9a24e68c
commit b18f547d8f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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);
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
{