DirTrees and unpacked archives shouldn't demand a count of entries for init.

This commit is contained in:
Ryan C. Gordon 2017-07-21 13:54:42 -04:00
parent 32ed71db48
commit d3ac612b61
11 changed files with 15 additions and 19 deletions

View File

@ -183,11 +183,11 @@ static int szipLoadEntry(SZIPinfo *info, const PHYSFS_uint32 idx)
static int szipLoadEntries(SZIPinfo *info)
{
const PHYSFS_uint32 count = info->db.NumFiles;
int retval = 0;
if (__PHYSFS_DirTreeInit(&info->tree, count, sizeof (SZIPentry)))
if (__PHYSFS_DirTreeInit(&info->tree, sizeof (SZIPentry)))
{
const PHYSFS_uint32 count = info->db.NumFiles;
PHYSFS_uint32 i;
for (i = 0; i < count; i++)
BAIL_IF_ERRPASS(!szipLoadEntry(info, i), 0);

View File

@ -73,7 +73,7 @@ static void *GRP_openArchive(PHYSFS_Io *io, const char *name, int forWriting)
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, &count, sizeof(count)), NULL);
count = PHYSFS_swapULE32(count);
unpkarc = UNPK_openArchive(io, count);
unpkarc = UNPK_openArchive(io);
BAIL_IF_ERRPASS(!unpkarc, NULL);
if (!grpLoadEntries(io, count, unpkarc))

View File

@ -72,7 +72,7 @@ static void *HOG_openArchive(PHYSFS_Io *io, const char *name, int forWriting)
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, buf, 3), NULL);
BAIL_IF(memcmp(buf, "DHF", 3) != 0, PHYSFS_ERR_UNSUPPORTED, NULL);
unpkarc = UNPK_openArchive(io, count);
unpkarc = UNPK_openArchive(io);
BAIL_IF_ERRPASS(!unpkarc, NULL);
if (!hogLoadEntries(io, unpkarc))

View File

@ -67,7 +67,7 @@ static void *MVL_openArchive(PHYSFS_Io *io, const char *name, int forWriting)
count = PHYSFS_swapULE32(count);
unpkarc = UNPK_openArchive(io, count);
unpkarc = UNPK_openArchive(io);
BAIL_IF_ERRPASS(!unpkarc, NULL);
if (!mvlLoadEntries(io, count, unpkarc))

View File

@ -83,7 +83,7 @@ static void *QPAK_openArchive(PHYSFS_Io *io, const char *name, int forWriting)
BAIL_IF_ERRPASS(!io->seek(io, pos), NULL);
unpkarc = UNPK_openArchive(io, count);
unpkarc = UNPK_openArchive(io);
BAIL_IF_ERRPASS(!unpkarc, NULL);
if (!qpakLoadEntries(io, count, unpkarc))

View File

@ -93,7 +93,7 @@ static void *SLB_openArchive(PHYSFS_Io *io, const char *name, int forWriting)
/* seek to the table of contents */
BAIL_IF_ERRPASS(!io->seek(io, tocPos), NULL);
unpkarc = UNPK_openArchive(io, count);
unpkarc = UNPK_openArchive(io);
BAIL_IF_ERRPASS(!unpkarc, NULL);
if (!slbLoadEntries(io, count, unpkarc))

View File

@ -271,12 +271,12 @@ void *UNPK_addEntry(void *opaque, char *name, const int isdir,
} /* UNPK_addEntry */
void *UNPK_openArchive(PHYSFS_Io *io, const PHYSFS_uint64 entry_count)
void *UNPK_openArchive(PHYSFS_Io *io)
{
UNPKinfo *info = (UNPKinfo *) allocator.Malloc(sizeof (UNPKinfo));
BAIL_IF(!info, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
if (!__PHYSFS_DirTreeInit(&info->tree, entry_count, sizeof (UNPKentry)))
if (!__PHYSFS_DirTreeInit(&info->tree, sizeof (UNPKentry)))
{
allocator.Free(info);
return NULL;

View File

@ -92,7 +92,7 @@ static void *WAD_openArchive(PHYSFS_Io *io, const char *name, int forWriting)
BAIL_IF_ERRPASS(!io->seek(io, directoryOffset), 0);
unpkarc = UNPK_openArchive(io, count);
unpkarc = UNPK_openArchive(io);
BAIL_IF_ERRPASS(!unpkarc, NULL);
if (!wadLoadEntries(io, count, unpkarc))

View File

@ -1472,7 +1472,7 @@ static void *ZIP_openArchive(PHYSFS_Io *io, const char *name, int forWriting)
if (!zip_parse_end_of_central_dir(info, &dstart, &cdir_ofs, &count))
goto ZIP_openarchive_failed;
else if (!__PHYSFS_DirTreeInit(&info->tree, count, sizeof (ZIPentry)))
else if (!__PHYSFS_DirTreeInit(&info->tree, sizeof (ZIPentry)))
goto ZIP_openarchive_failed;
root = (ZIPentry *) info->tree.root;

View File

@ -3008,9 +3008,7 @@ static void setDefaultAllocator(void)
} /* setDefaultAllocator */
int __PHYSFS_DirTreeInit(__PHYSFS_DirTree *dt,
const PHYSFS_uint64 entry_count,
const size_t entrylen)
int __PHYSFS_DirTreeInit(__PHYSFS_DirTree *dt, const size_t entrylen)
{
static char rootpath[2] = { '/', '\0' };
size_t alloclen;
@ -3024,7 +3022,7 @@ int __PHYSFS_DirTreeInit(__PHYSFS_DirTree *dt,
memset(dt->root, '\0', entrylen);
dt->root->name = rootpath;
dt->root->isdir = 1;
dt->hashBuckets = (size_t) (entry_count / 5);
dt->hashBuckets = 64;
if (!dt->hashBuckets)
dt->hashBuckets = 1;
dt->entrylen = entrylen;

View File

@ -343,7 +343,7 @@ int __PHYSFS_readAll(PHYSFS_Io *io, void *buf, const PHYSFS_uint64 len);
/* These are shared between some archivers. */
void UNPK_closeArchive(void *opaque);
void *UNPK_openArchive(PHYSFS_Io *io, const PHYSFS_uint64 entry_count);
void *UNPK_openArchive(PHYSFS_Io *io);
void *UNPK_addEntry(void *opaque, char *name, const int isdir,
const PHYSFS_uint64 pos, const PHYSFS_uint64 len);
PHYSFS_Io *UNPK_openRead(void *opaque, const char *name);
@ -377,9 +377,7 @@ typedef struct __PHYSFS_DirTree
} __PHYSFS_DirTree;
int __PHYSFS_DirTreeInit(__PHYSFS_DirTree *dt,
const PHYSFS_uint64 entry_count,
const size_t entrylen);
int __PHYSFS_DirTreeInit(__PHYSFS_DirTree *dt, const size_t entrylen);
void *__PHYSFS_DirTreeAdd(__PHYSFS_DirTree *dt, char *name, const int isdir);
void *__PHYSFS_DirTreeFind(__PHYSFS_DirTree *dt, const char *path);
void __PHYSFS_DirTreeEnumerateFiles(void *opaque, const char *dname,