Browse Source

SDL_InternalGlobDirectory(): set string length of base directory to 1, if it's just one slash

(cherry picked from commit 67ac0e5eeef5a3af7e858c1cf6d4b2be15c3d223)
Petar Popovic 1 week ago
parent
commit
7280152549
1 changed files with 8 additions and 1 deletions
  1. 8 1
      src/filesystem/SDL_filesystem.c

+ 8 - 1
src/filesystem/SDL_filesystem.c

@@ -426,8 +426,15 @@ char **SDL_InternalGlobDirectory(const char *path, const char *pattern, SDL_Glob
     data.enumerator = enumerator;
     data.getpathinfo = getpathinfo;
     data.fsuserdata = userdata;
-    data.basedirlen = *path ? (pathlen + 1) : 0;  // +1 for the '/' we'll be adding.
 
+    data.basedirlen = 0;
+    if (*path) {
+        if (SDL_strcmp(path, "/") == 0 || SDL_strcmp(path, "\\") == 0) {
+            data.basedirlen = 1;
+        } else {
+            data.basedirlen = pathlen + 1; // +1 for the '/' we'll be adding.
+        }
+    }
 
     char **result = NULL;
     if (data.enumerator(path, GlobDirectoryCallback, &data, data.fsuserdata)) {