From d3ac612b6176b4994abec0392a7b7878d4b32f84 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Fri, 21 Jul 2017 13:54:42 -0400 Subject: [PATCH] DirTrees and unpacked archives shouldn't demand a count of entries for init. --- src/archiver_7z.c | 4 ++-- src/archiver_grp.c | 2 +- src/archiver_hog.c | 2 +- src/archiver_mvl.c | 2 +- src/archiver_qpak.c | 2 +- src/archiver_slb.c | 2 +- src/archiver_unpacked.c | 4 ++-- src/archiver_wad.c | 2 +- src/archiver_zip.c | 2 +- src/physfs.c | 6 ++---- src/physfs_internal.h | 6 ++---- 11 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/archiver_7z.c b/src/archiver_7z.c index 4f692c16..bdfafe1d 100644 --- a/src/archiver_7z.c +++ b/src/archiver_7z.c @@ -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); diff --git a/src/archiver_grp.c b/src/archiver_grp.c index ec233c14..70bd0112 100644 --- a/src/archiver_grp.c +++ b/src/archiver_grp.c @@ -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)) diff --git a/src/archiver_hog.c b/src/archiver_hog.c index c6dee0d6..7de9752f 100644 --- a/src/archiver_hog.c +++ b/src/archiver_hog.c @@ -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)) diff --git a/src/archiver_mvl.c b/src/archiver_mvl.c index da04af9b..6bca8db1 100644 --- a/src/archiver_mvl.c +++ b/src/archiver_mvl.c @@ -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)) diff --git a/src/archiver_qpak.c b/src/archiver_qpak.c index 759cfae4..c4ef24cc 100644 --- a/src/archiver_qpak.c +++ b/src/archiver_qpak.c @@ -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)) diff --git a/src/archiver_slb.c b/src/archiver_slb.c index 26466eaf..e209aa60 100644 --- a/src/archiver_slb.c +++ b/src/archiver_slb.c @@ -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)) diff --git a/src/archiver_unpacked.c b/src/archiver_unpacked.c index 184ad665..98b90357 100644 --- a/src/archiver_unpacked.c +++ b/src/archiver_unpacked.c @@ -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; diff --git a/src/archiver_wad.c b/src/archiver_wad.c index c385c937..73f7d363 100644 --- a/src/archiver_wad.c +++ b/src/archiver_wad.c @@ -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)) diff --git a/src/archiver_zip.c b/src/archiver_zip.c index 7f071b44..b9911e46 100644 --- a/src/archiver_zip.c +++ b/src/archiver_zip.c @@ -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; diff --git a/src/physfs.c b/src/physfs.c index fc0abb8b..7800263f 100644 --- a/src/physfs.c +++ b/src/physfs.c @@ -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; diff --git a/src/physfs_internal.h b/src/physfs_internal.h index 954010af..47f9a3af 100644 --- a/src/physfs_internal.h +++ b/src/physfs_internal.h @@ -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,