SDL: Only use the default gamepad mapping if an automatic mapping isn't available

From 0f8054cf87e6b221659acca70d2471e05f2133e1 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 3 Jul 2024 11:43:43 -0700
Subject: [PATCH] Only use the default gamepad mapping if an automatic mapping
 isn't available

Fixes https://github.com/libsdl-org/SDL/issues/10162
---
 src/joystick/SDL_gamepad.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/joystick/SDL_gamepad.c b/src/joystick/SDL_gamepad.c
index 833cfae42ec0d..bf1c5b35a6062 100644
--- a/src/joystick/SDL_gamepad.c
+++ b/src/joystick/SDL_gamepad.c
@@ -1676,9 +1676,6 @@ static GamepadMapping_t *SDL_PrivateGetGamepadMappingForNameAndGUID(const char *
     }
 #endif /* SDL_PLATFORM_LINUX */
 
-    if (!mapping) {
-        mapping = s_pDefaultMapping;
-    }
     return mapping;
 }
 
@@ -1793,6 +1790,9 @@ static GamepadMapping_t *SDL_PrivateGetGamepadMapping(SDL_JoystickID instance_id
         }
     }
 
+    if (!mapping) {
+        mapping = s_pDefaultMapping;
+    }
     return mapping;
 }
 
@@ -2546,7 +2546,7 @@ SDL_bool SDL_IsGamepadNameAndGUID(const char *name, SDL_JoystickGUID guid)
 
     SDL_LockJoysticks();
     {
-        if (SDL_PrivateGetGamepadMappingForNameAndGUID(name, guid) != NULL) {
+        if (s_pDefaultMapping || SDL_PrivateGetGamepadMappingForNameAndGUID(name, guid) != NULL) {
             retval = SDL_TRUE;
         } else {
             retval = SDL_FALSE;