Browse Source

Check for NULL before dereferencing newly allocated memory

Fixes https://github.com/libsdl-org/SDL/issues/8289
Sam Lantinga 1 year ago
parent
commit
70a1bc6973
1 changed files with 1 additions and 1 deletions
  1. 1 1
      src/joystick/linux/SDL_sysjoystick.c

+ 1 - 1
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 *)