Runtime fixes for the pak file handling, should not segfault anymore..

This commit is contained in:
Zephaniah E. Hull 2000-04-01 06:26:03 +00:00
parent e0cf6cad56
commit 955c3d03a2

View file

@ -725,14 +725,18 @@ COM_LoadGameDirectory(char *dir)
pack_t *pak;
DIR *dir_ptr;
struct dirent *dirent;
char **pakfiles;
char **pakfiles = NULL;
int i = 0, bufsize = 0, count = 0;
pakfiles = calloc(1, FBLOCK_SIZE);
pakfiles = malloc(FBLOCK_SIZE * sizeof(char *));
bufsize += FBLOCK_SIZE;
if (!pakfiles)
goto COM_LoadGameDirectory_free;
for (i = count; i < bufsize; i++) {
pakfiles[i] = NULL;
}
dir_ptr = opendir(dir);
if (!dir_ptr)
return;
@ -741,12 +745,13 @@ COM_LoadGameDirectory(char *dir)
if (!fnmatch("*.pak", dirent->d_name, FNMATCH_FLAGS)) {
if (count >= bufsize) {
bufsize += FBLOCK_SIZE;
pakfiles = realloc(pakfiles, bufsize);
pakfiles = realloc(pakfiles, bufsize * sizeof(char *));
if (!pakfiles)
goto COM_LoadGameDirectory_free;
for (i = count; i < bufsize; i++)
pakfiles[i] = NULL;
}
pakfiles[count] = malloc(FNAME_SIZE);
snprintf(pakfiles[count], FNAME_SIZE - 1, "%s/%s", dir,
dirent->d_name);
@ -756,8 +761,8 @@ COM_LoadGameDirectory(char *dir)
}
closedir(dir_ptr);
qsort(pakfiles, count, FNAME_SIZE,
(int (*)(const void *, const void *)) Q_qstrcmp);
qsort(pakfiles, count - 1, sizeof(char *),
(int (*)(const void *, const void *)) strcmp);
for (i = 0; i < count; i++) {
pak = COM_LoadPackFile(pakfiles[i]);