Skip to content

Commit a703538

Browse files
Sackzementslouken
authored andcommitted
SDL_InternalGlobDirectory(): keep track of pathlen and reuse it, instead of calling SDL_strlen(path)
(cherry picked from commit 93e3e8a)
1 parent fb312b2 commit a703538

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/filesystem/SDL_filesystem.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ char **SDL_InternalGlobDirectory(const char *path, const char *pattern, SDL_Glob
382382
char *ptr = &pathcpy[pathlen-1];
383383
while ((ptr > pathcpy) && ((*ptr == '/') || (*ptr == '\\'))) {
384384
*(ptr--) = '\0';
385+
--pathlen;
385386
}
386387
path = pathcpy;
387388
}
@@ -425,7 +426,7 @@ char **SDL_InternalGlobDirectory(const char *path, const char *pattern, SDL_Glob
425426
data.enumerator = enumerator;
426427
data.getpathinfo = getpathinfo;
427428
data.fsuserdata = userdata;
428-
data.basedirlen = *path ? (SDL_strlen(path) + 1) : 0; // +1 for the '/' we'll be adding.
429+
data.basedirlen = *path ? (pathlen + 1) : 0; // +1 for the '/' we'll be adding.
429430

430431

431432
char **result = NULL;

0 commit comments

Comments
 (0)