mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2024-11-15 09:11:48 +00:00
zentries is unnecessary
This commit is contained in:
parent
ee9aa86ecd
commit
fb7c4ab812
1 changed files with 13 additions and 21 deletions
34
src/w_wad.c
34
src/w_wad.c
|
@ -527,8 +527,7 @@ typedef struct zlentry_s
|
|||
static lumpinfo_t* ResGetLumpsZip (FILE* handle, UINT16* nlmp)
|
||||
{
|
||||
zend_t zend;
|
||||
zentry_t* zentries;
|
||||
zentry_t* zentry;
|
||||
zentry_t zentry;
|
||||
zlentry_t zlentry;
|
||||
|
||||
UINT16 numlumps = *nlmp;
|
||||
|
@ -557,40 +556,36 @@ static lumpinfo_t* ResGetLumpsZip (FILE* handle, UINT16* nlmp)
|
|||
numlumps = zend.entries;
|
||||
|
||||
lump_p = lumpinfo = Z_Malloc(numlumps * sizeof (*lumpinfo), PU_STATIC, NULL);
|
||||
zentry = zentries = malloc(numlumps * sizeof (*zentries));
|
||||
|
||||
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* trimname;
|
||||
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));
|
||||
Z_Free(lumpinfo);
|
||||
free(zentries);
|
||||
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");
|
||||
Z_Free(lumpinfo);
|
||||
free(zentries);
|
||||
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->disksize = zentry->compsize;
|
||||
lump_p->size = zentry->size;
|
||||
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->size = zentry.size;
|
||||
|
||||
fullname = malloc(zentry->namelen + 1);
|
||||
if (fgets(fullname, zentry->namelen + 1, handle) != fullname)
|
||||
fullname = malloc(zentry.namelen + 1);
|
||||
if (fgets(fullname, zentry.namelen + 1, handle) != fullname)
|
||||
{
|
||||
CONS_Alert(CONS_ERROR, "Unable to read lumpname (%s)\n", M_FileError(handle));
|
||||
Z_Free(lumpinfo);
|
||||
free(zentries);
|
||||
free(fullname);
|
||||
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?
|
||||
strncpy(lump_p->name, trimname, min(8, dotpos - trimname));
|
||||
|
||||
lump_p->name2 = Z_Calloc(zentry->namelen + 1, PU_STATIC, NULL);
|
||||
strncpy(lump_p->name2, fullname, zentry->namelen);
|
||||
lump_p->name2 = Z_Calloc(zentry.namelen + 1, PU_STATIC, NULL);
|
||||
strncpy(lump_p->name2, fullname, zentry.namelen);
|
||||
|
||||
free(fullname);
|
||||
|
||||
switch(zentry->compression)
|
||||
switch(zentry.compression)
|
||||
{
|
||||
case 0:
|
||||
lump_p->compression = CM_NOCOMPRESSION;
|
||||
|
@ -632,17 +627,14 @@ static lumpinfo_t* ResGetLumpsZip (FILE* handle, UINT16* nlmp)
|
|||
}
|
||||
|
||||
// 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");
|
||||
Z_Free(lumpinfo);
|
||||
free(zentries);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
free(zentries);
|
||||
|
||||
// Adjust lump position values properly
|
||||
for (i = 0, lump_p = lumpinfo; i < numlumps; i++, lump_p++)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue