From 85eb1fa5150447e127d7c0a2baeed962a2a3223f Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 18 Jul 2023 17:32:46 -0700 Subject: [PATCH] Fixed double-comma if the crc is first in the mapping --- src/joystick/SDL_gamepad.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/joystick/SDL_gamepad.c b/src/joystick/SDL_gamepad.c index 6d26b3982..901c1a465 100644 --- a/src/joystick/SDL_gamepad.c +++ b/src/joystick/SDL_gamepad.c @@ -1465,6 +1465,7 @@ static GamepadMapping_t *SDL_PrivateAddMappingForGUID(SDL_JoystickGUID jGUID, co /* Make sure the mapping has the CRC */ char *new_mapping; const char *optional_comma; + size_t mapping_length; char *crc_end = ""; char *crc_string = SDL_strstr(pchMapping, SDL_GAMEPAD_CRC_FIELD); if (crc_string) { @@ -1478,7 +1479,8 @@ static GamepadMapping_t *SDL_PrivateAddMappingForGUID(SDL_JoystickGUID jGUID, co } /* Make sure there's a comma before the CRC */ - if (pchMapping[SDL_strlen(pchMapping) - 1] == ',') { + mapping_length = SDL_strlen(pchMapping); + if (mapping_length == 0 || pchMapping[mapping_length - 1] == ',') { optional_comma = ""; } else { optional_comma = ",";