Skip to content

Commit

Permalink
DirTrees and unpacked archives shouldn't demand a count of entries fo…
Browse files Browse the repository at this point in the history
…r init.
  • Loading branch information
icculus committed Jul 21, 2017
1 parent 32ed71d commit d3ac612
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/archiver_7z.c
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/archiver_grp.c
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion src/archiver_hog.c
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion src/archiver_mvl.c
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion src/archiver_qpak.c
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion src/archiver_slb.c
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions src/archiver_unpacked.c
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/archiver_wad.c
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion src/archiver_zip.c
Expand Up @@ -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;
Expand Down
6 changes: 2 additions & 4 deletions src/physfs.c
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
6 changes: 2 additions & 4 deletions src/physfs_internal.h
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit d3ac612

Please sign in to comment.