Procházet zdrojové kódy

storage: generic title storage allows override paths without '/' appended.

Fixes #11299.
Ryan C. Gordon před 3 měsíci
rodič
revize
3ffb1a8cbd
1 změnil soubory, kde provedl 7 přidání a 2 odebrání
  1. 7 2
      src/storage/generic/SDL_genericstorage.c

+ 7 - 2
src/storage/generic/SDL_genericstorage.c

@@ -236,10 +236,15 @@ static const SDL_StorageInterface GENERIC_title_iface = {
 static SDL_Storage *GENERIC_Title_Create(const char *override, SDL_PropertiesID props)
 {
     SDL_Storage *result = NULL;
-
     char *basepath = NULL;
+
     if (override != NULL) {
-        basepath = SDL_strdup(override);
+        // make sure override has a path separator at the end. If you're not on Windows and used '\\', that's on you.
+        const size_t slen = SDL_strlen(override);
+        const bool need_sep = (!slen || ((override[slen-1] != '/') && (override[slen-1] != '\\')));
+        if (SDL_asprintf(&basepath, "%s%s", override, need_sep ? "/" : "") == -1) {
+            return NULL;
+        }
     } else {
         const char *base = SDL_GetBasePath();
         basepath = base ? SDL_strdup(base) : NULL;