Skip to content

Commit

Permalink
BUG: use size_t for holding the size of a directory, otherwise we ove…
Browse files Browse the repository at this point in the history
…rflow on larger directories and never clean things up. also, continue iterating through files once we've hit the limit, we will stop appending new values to the files array but continue calculating directory size. this is related to issue #135
  • Loading branch information
ciscon committed May 10, 2024
1 parent 3925960 commit cf48f59
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/sv_sys_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ int Sys_FileTime (const char *path)
return stat(path, &buf) == -1 ? -1 : buf.st_mtime;
}

int Sys_FileSizeTime (char *path, int *time1)
int Sys_FileSizeTime (char *path, time_t *time1)
{
struct stat buf;
if (stat(path, &buf) == -1)
Expand Down Expand Up @@ -179,8 +179,8 @@ dir_t Sys_listdir (const char *path, const char *ext, int sort_type)
}
strlcpy (list[dir.numfiles].name, oneentry->d_name, MAX_DEMO_NAME);

if (++dir.numfiles == MAX_DIRFILES - 1)
break;
if (dir.numfiles != MAX_DIRFILES - 1) dir.numfiles++;

}
closedir(d);
if (!all)
Expand Down
3 changes: 1 addition & 2 deletions src/sv_sys_win.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,7 @@ dir_t Sys_listdir (const char *path, const char *ext, int sort_type)
}
strlcpy (list[dir.numfiles].name, fd.cFileName, sizeof(list[0].name));

if (++dir.numfiles == MAX_DIRFILES - 1)
break;
if (dir.numfiles != MAX_DIRFILES - 1) dir.numfiles++;

}
while (FindNextFile(h, &fd));
Expand Down
12 changes: 6 additions & 6 deletions src/sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
typedef struct
{
char name[MAX_DEMO_NAME];
int size;
int time;
size_t size;
time_t time;
qbool isdir; //bliP: list dir
} file_t;

typedef struct
{
file_t *files;
int size;
int numfiles;
int numdirs;
file_t *files;
size_t size;
size_t numfiles;
size_t numdirs;
} dir_t;

int Sys_FileTime (const char *path);
Expand Down

0 comments on commit cf48f59

Please sign in to comment.