From 70a1bc69739016884a22abe6bf86f8a5deba29ef Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 24 Sep 2023 17:17:49 -0700 Subject: [PATCH] Check for NULL before dereferencing newly allocated memory Fixes https://github.com/libsdl-org/SDL/issues/8289 --- src/joystick/linux/SDL_sysjoystick.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/joystick/linux/SDL_sysjoystick.c b/src/joystick/linux/SDL_sysjoystick.c index cca2016e5..992a0d824 100644 --- a/src/joystick/linux/SDL_sysjoystick.c +++ b/src/joystick/linux/SDL_sysjoystick.c @@ -2116,11 +2116,11 @@ static SDL_bool LINUX_JoystickGetGamepadMapping(int device_index, SDL_GamepadMap /* We temporarily open the device to check how it's configured. Make a fake SDL_Joystick object to do so. */ joystick = (SDL_Joystick *)SDL_calloc(sizeof(*joystick), 1); - joystick->magic = &SDL_joystick_magic; if (joystick == NULL) { SDL_OutOfMemory(); return SDL_FALSE; } + joystick->magic = &SDL_joystick_magic; SDL_memcpy(&joystick->guid, &item->guid, sizeof(item->guid)); joystick->hwdata = (struct joystick_hwdata *)