Przeglądaj źródła

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.
pull/5362/head
MikiZX1 1 miesiąc temu
committed by GitHub
rodzic
commit
b18f547d8f
Nie znaleziono w bazie danych klucza dla tego podpisu ID klucza GPG: B5690EEEBB952194
1 zmienionych plików z 4 dodań i 1 usunięć
  1. +4
    -1
      src/platforms/rcore_desktop_sdl.c

+ 4
- 1
src/platforms/rcore_desktop_sdl.c Wyświetl plik

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

Ładowanie…
Anuluj
Zapisz