mirror of
https://git.code.sf.net/p/quake/quakeforge-old
synced 2024-11-22 11:51:17 +00:00
Runtime fixes for the pak file handling, should not segfault anymore..
This commit is contained in:
parent
e0cf6cad56
commit
955c3d03a2
1 changed files with 10 additions and 5 deletions
|
@ -725,14 +725,18 @@ COM_LoadGameDirectory(char *dir)
|
||||||
pack_t *pak;
|
pack_t *pak;
|
||||||
DIR *dir_ptr;
|
DIR *dir_ptr;
|
||||||
struct dirent *dirent;
|
struct dirent *dirent;
|
||||||
char **pakfiles;
|
char **pakfiles = NULL;
|
||||||
int i = 0, bufsize = 0, count = 0;
|
int i = 0, bufsize = 0, count = 0;
|
||||||
|
|
||||||
pakfiles = calloc(1, FBLOCK_SIZE);
|
pakfiles = malloc(FBLOCK_SIZE * sizeof(char *));
|
||||||
bufsize += FBLOCK_SIZE;
|
bufsize += FBLOCK_SIZE;
|
||||||
if (!pakfiles)
|
if (!pakfiles)
|
||||||
goto COM_LoadGameDirectory_free;
|
goto COM_LoadGameDirectory_free;
|
||||||
|
|
||||||
|
for (i = count; i < bufsize; i++) {
|
||||||
|
pakfiles[i] = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
dir_ptr = opendir(dir);
|
dir_ptr = opendir(dir);
|
||||||
if (!dir_ptr)
|
if (!dir_ptr)
|
||||||
return;
|
return;
|
||||||
|
@ -741,12 +745,13 @@ COM_LoadGameDirectory(char *dir)
|
||||||
if (!fnmatch("*.pak", dirent->d_name, FNMATCH_FLAGS)) {
|
if (!fnmatch("*.pak", dirent->d_name, FNMATCH_FLAGS)) {
|
||||||
if (count >= bufsize) {
|
if (count >= bufsize) {
|
||||||
bufsize += FBLOCK_SIZE;
|
bufsize += FBLOCK_SIZE;
|
||||||
pakfiles = realloc(pakfiles, bufsize);
|
pakfiles = realloc(pakfiles, bufsize * sizeof(char *));
|
||||||
if (!pakfiles)
|
if (!pakfiles)
|
||||||
goto COM_LoadGameDirectory_free;
|
goto COM_LoadGameDirectory_free;
|
||||||
for (i = count; i < bufsize; i++)
|
for (i = count; i < bufsize; i++)
|
||||||
pakfiles[i] = NULL;
|
pakfiles[i] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pakfiles[count] = malloc(FNAME_SIZE);
|
pakfiles[count] = malloc(FNAME_SIZE);
|
||||||
snprintf(pakfiles[count], FNAME_SIZE - 1, "%s/%s", dir,
|
snprintf(pakfiles[count], FNAME_SIZE - 1, "%s/%s", dir,
|
||||||
dirent->d_name);
|
dirent->d_name);
|
||||||
|
@ -756,8 +761,8 @@ COM_LoadGameDirectory(char *dir)
|
||||||
}
|
}
|
||||||
closedir(dir_ptr);
|
closedir(dir_ptr);
|
||||||
|
|
||||||
qsort(pakfiles, count, FNAME_SIZE,
|
qsort(pakfiles, count - 1, sizeof(char *),
|
||||||
(int (*)(const void *, const void *)) Q_qstrcmp);
|
(int (*)(const void *, const void *)) strcmp);
|
||||||
|
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
pak = COM_LoadPackFile(pakfiles[i]);
|
pak = COM_LoadPackFile(pakfiles[i]);
|
||||||
|
|
Loading…
Reference in a new issue