[lonetix/fs] Make Sys_ListFiles() safer when NULL is returned, by clearing *nfiles

This commit is contained in:
Lorenzo Cogotti 2021-10-15 11:51:14 +02:00
parent c195ecd8d7
commit dbd36e302c
1 changed files with 7 additions and 0 deletions

View File

@ -215,6 +215,9 @@ char **Sys_ListFiles(const char *path, unsigned *nfiles, const char *pat)
if (errno != ENOENT && errno != ENOTDIR) if (errno != ENOENT && errno != ENOTDIR)
Sys_SetErrStat(errno, "opendir()"); Sys_SetErrStat(errno, "opendir()");
if (nfiles)
*nfiles = 0;
return NULL; return NULL;
} }
@ -321,6 +324,10 @@ char **Sys_ListFiles(const char *path, unsigned *nfiles, const char *pat)
fail: fail:
closedir(dir); closedir(dir);
if (nfiles)
*nfiles = 0;
return NULL; return NULL;
} }