From 8b31e0d3b65017d6afa1f6274f8bd4c2b73c4000 Mon Sep 17 00:00:00 2001 From: Professor Hastig Date: Wed, 13 Sep 2023 09:47:09 +0200 Subject: [PATCH] - fix bad stringpool setup in filesystem. Doing it in the constructor does not work because InitMultipleFiles will clear everything again before building up the directory so it would always be null. This triggered another bug in file_directory.cpp which used the constructor's unvalidated parameter. --- src/common/filesystem/include/fs_filesystem.h | 2 +- src/common/filesystem/source/file_directory.cpp | 2 +- src/common/filesystem/source/filesystem.cpp | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/common/filesystem/include/fs_filesystem.h b/src/common/filesystem/include/fs_filesystem.h index b559494084..bac46e1bb0 100644 --- a/src/common/filesystem/include/fs_filesystem.h +++ b/src/common/filesystem/include/fs_filesystem.h @@ -202,7 +202,7 @@ protected: int IwadIndex = -1; int MaxIwadIndex = -1; - StringPool* stringpool; + StringPool* stringpool = nullptr; private: void DeleteAll(); diff --git a/src/common/filesystem/source/file_directory.cpp b/src/common/filesystem/source/file_directory.cpp index 84679ffc91..89b9625fc6 100644 --- a/src/common/filesystem/source/file_directory.cpp +++ b/src/common/filesystem/source/file_directory.cpp @@ -96,7 +96,7 @@ FDirectory::FDirectory(const char * directory, StringPool* sp, bool nosubdirflag { auto fn = FS_FullPath(directory); if (fn.back() != '/') fn += '/'; - FileName = sp->Strdup(fn.c_str()); + FileName = stringpool->Strdup(fn.c_str()); } //========================================================================== diff --git a/src/common/filesystem/source/filesystem.cpp b/src/common/filesystem/source/filesystem.cpp index c22682ec0a..cc810cc2e2 100644 --- a/src/common/filesystem/source/filesystem.cpp +++ b/src/common/filesystem/source/filesystem.cpp @@ -194,8 +194,6 @@ static void PrintLastError (FileSystemMessageFunc Printf); FileSystem::FileSystem() { - stringpool = new StringPool(true); - stringpool->shared = true; // will be used by all owned resource files. } FileSystem::~FileSystem () @@ -219,7 +217,7 @@ void FileSystem::DeleteAll () delete Files[i]; } Files.clear(); - delete stringpool; + if (stringpool != nullptr) delete stringpool; stringpool = nullptr; } @@ -248,6 +246,9 @@ bool FileSystem::InitMultipleFiles (std::vector& filenames, LumpFil DeleteAll(); numfiles = 0; + stringpool = new StringPool(true); + stringpool->shared = true; // will be used by all owned resource files. + // first, check for duplicates if (allowduplicates) {