SDL: Add '/' to GetUserFolder(HOME) on Cocoa & Unix

From 0178b194897926cc3e5c4745fbbbeaa6592dc9f5 Mon Sep 17 00:00:00 2001
From: Semphris <[EMAIL REDACTED]>
Date: Thu, 2 May 2024 11:29:14 -0400
Subject: [PATCH] Add '/' to GetUserFolder(HOME) on Cocoa & Unix

---
 src/filesystem/cocoa/SDL_sysfilesystem.m | 4 +++-
 src/filesystem/unix/SDL_sysfilesystem.c  | 4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/filesystem/cocoa/SDL_sysfilesystem.m b/src/filesystem/cocoa/SDL_sysfilesystem.m
index fb261d769916f..7491953bdacfd 100644
--- a/src/filesystem/cocoa/SDL_sysfilesystem.m
+++ b/src/filesystem/cocoa/SDL_sysfilesystem.m
@@ -146,9 +146,10 @@
 
             if (!base) {
                 SDL_SetError("No $HOME environment variable available");
+                return NULL;
             }
 
-            return SDL_strdup(base);
+            goto append_slash;
 
         case SDL_FOLDER_DESKTOP:
             dir = NSDesktopDirectory;
@@ -209,6 +210,7 @@
             return NULL;
         }
 
+append_slash:
         retval = SDL_malloc(SDL_strlen(base) + 2);
         if (retval == NULL) {
             return NULL;
diff --git a/src/filesystem/unix/SDL_sysfilesystem.c b/src/filesystem/unix/SDL_sysfilesystem.c
index 308950edd70a7..70a5ee6b414bb 100644
--- a/src/filesystem/unix/SDL_sysfilesystem.c
+++ b/src/filesystem/unix/SDL_sysfilesystem.c
@@ -535,7 +535,8 @@ char *SDL_GetUserFolder(SDL_Folder folder)
             return NULL;
         }
 
-        return SDL_strdup(param);
+        retval = SDL_strdup(param);
+        goto append_slash;
 
     case SDL_FOLDER_DESKTOP:
         param = "DESKTOP";
@@ -595,6 +596,7 @@ char *SDL_GetUserFolder(SDL_Folder folder)
         return NULL;
     }
 
+append_slash:
     newretval = (char *) SDL_realloc(retval, SDL_strlen(retval) + 2);
 
     if (!newretval) {