zentries is unnecessary

This commit is contained in:
fickleheart 2020-02-07 18:47:56 -06:00
parent ee9aa86ecd
commit fb7c4ab812
1 changed files with 13 additions and 21 deletions

View File

@ -527,8 +527,7 @@ typedef struct zlentry_s
static lumpinfo_t* ResGetLumpsZip (FILE* handle, UINT16* nlmp) static lumpinfo_t* ResGetLumpsZip (FILE* handle, UINT16* nlmp)
{ {
zend_t zend; zend_t zend;
zentry_t* zentries; zentry_t zentry;
zentry_t* zentry;
zlentry_t zlentry; zlentry_t zlentry;
UINT16 numlumps = *nlmp; UINT16 numlumps = *nlmp;
@ -557,40 +556,36 @@ static lumpinfo_t* ResGetLumpsZip (FILE* handle, UINT16* nlmp)
numlumps = zend.entries; numlumps = zend.entries;
lump_p = lumpinfo = Z_Malloc(numlumps * sizeof (*lumpinfo), PU_STATIC, NULL); lump_p = lumpinfo = Z_Malloc(numlumps * sizeof (*lumpinfo), PU_STATIC, NULL);
zentry = zentries = malloc(numlumps * sizeof (*zentries));
fseek(handle, zend.cdiroffset, SEEK_SET); fseek(handle, zend.cdiroffset, SEEK_SET);
for (i = 0; i < numlumps; i++, zentry++, lump_p++) for (i = 0; i < numlumps; i++, lump_p++)
{ {
char* fullname; char* fullname;
char* trimname; char* trimname;
char* dotpos; char* dotpos;
if (fread(zentry, 1, sizeof(zentry_t), handle) < sizeof(zentry_t)) if (fread(&zentry, 1, sizeof(zentry_t), handle) < sizeof(zentry_t))
{ {
CONS_Alert(CONS_ERROR, "Failed to read central directory (%s)\n", M_FileError(handle)); CONS_Alert(CONS_ERROR, "Failed to read central directory (%s)\n", M_FileError(handle));
Z_Free(lumpinfo); Z_Free(lumpinfo);
free(zentries);
return NULL; return NULL;
} }
if (memcmp(zentry->signature, pat_central, 4)) if (memcmp(zentry.signature, pat_central, 4))
{ {
CONS_Alert(CONS_ERROR, "Central directory is corrupt\n"); CONS_Alert(CONS_ERROR, "Central directory is corrupt\n");
Z_Free(lumpinfo); Z_Free(lumpinfo);
free(zentries);
return NULL; return NULL;
} }
lump_p->position = zentry->offset; // NOT ACCURATE YET: we still need to read the local entry to find our true position lump_p->position = zentry.offset; // NOT ACCURATE YET: we still need to read the local entry to find our true position
lump_p->disksize = zentry->compsize; lump_p->disksize = zentry.compsize;
lump_p->size = zentry->size; lump_p->size = zentry.size;
fullname = malloc(zentry->namelen + 1); fullname = malloc(zentry.namelen + 1);
if (fgets(fullname, zentry->namelen + 1, handle) != fullname) if (fgets(fullname, zentry.namelen + 1, handle) != fullname)
{ {
CONS_Alert(CONS_ERROR, "Unable to read lumpname (%s)\n", M_FileError(handle)); CONS_Alert(CONS_ERROR, "Unable to read lumpname (%s)\n", M_FileError(handle));
Z_Free(lumpinfo); Z_Free(lumpinfo);
free(zentries);
free(fullname); free(fullname);
return NULL; return NULL;
} }
@ -607,12 +602,12 @@ static lumpinfo_t* ResGetLumpsZip (FILE* handle, UINT16* nlmp)
memset(lump_p->name, '\0', 9); // Making sure they're initialized to 0. Is it necessary? memset(lump_p->name, '\0', 9); // Making sure they're initialized to 0. Is it necessary?
strncpy(lump_p->name, trimname, min(8, dotpos - trimname)); strncpy(lump_p->name, trimname, min(8, dotpos - trimname));
lump_p->name2 = Z_Calloc(zentry->namelen + 1, PU_STATIC, NULL); lump_p->name2 = Z_Calloc(zentry.namelen + 1, PU_STATIC, NULL);
strncpy(lump_p->name2, fullname, zentry->namelen); strncpy(lump_p->name2, fullname, zentry.namelen);
free(fullname); free(fullname);
switch(zentry->compression) switch(zentry.compression)
{ {
case 0: case 0:
lump_p->compression = CM_NOCOMPRESSION; lump_p->compression = CM_NOCOMPRESSION;
@ -632,17 +627,14 @@ static lumpinfo_t* ResGetLumpsZip (FILE* handle, UINT16* nlmp)
} }
// skip and ignore comments/extra fields // skip and ignore comments/extra fields
if (fseek(handle, zentry->xtralen + zentry->commlen, SEEK_CUR) != 0) if (fseek(handle, zentry.xtralen + zentry.commlen, SEEK_CUR) != 0)
{ {
CONS_Alert(CONS_ERROR, "Central directory is corrupt\n"); CONS_Alert(CONS_ERROR, "Central directory is corrupt\n");
Z_Free(lumpinfo); Z_Free(lumpinfo);
free(zentries);
return NULL; return NULL;
} }
} }
free(zentries);
// Adjust lump position values properly // Adjust lump position values properly
for (i = 0, lump_p = lumpinfo; i < numlumps; i++, lump_p++) for (i = 0, lump_p = lumpinfo; i < numlumps; i++, lump_p++)
{ {