Просмотр исходного кода

SDL_InternalGlobDirectory(): keep track of pathlen and reuse it, instead of calling SDL_strlen(path)

Petar Popovic 4 дней назад
Родитель
Сommit
93e3e8a5fe
1 измененных файлов с 2 добавлено и 1 удалено
  1. 2 1
      src/filesystem/SDL_filesystem.c

+ 2 - 1
src/filesystem/SDL_filesystem.c

@@ -382,6 +382,7 @@ char **SDL_InternalGlobDirectory(const char *path, const char *pattern, SDL_Glob
         char *ptr = &pathcpy[pathlen-1];
         while ((ptr > pathcpy) && ((*ptr == '/') || (*ptr == '\\'))) {
             *(ptr--) = '\0';
+            --pathlen;
         }
         path = pathcpy;
     }
@@ -425,7 +426,7 @@ char **SDL_InternalGlobDirectory(const char *path, const char *pattern, SDL_Glob
     data.enumerator = enumerator;
     data.getpathinfo = getpathinfo;
     data.fsuserdata = userdata;
-    data.basedirlen = *path ? (SDL_strlen(path) + 1) : 0;  // +1 for the '/' we'll be adding.
+    data.basedirlen = *path ? (pathlen + 1) : 0;  // +1 for the '/' we'll be adding.
 
 
     char **result = NULL;