From e6e9ad2bc81868d93038b5e5198e31b19cdec265 Mon Sep 17 00:00:00 2001 From: Haaxor1689 Date: Mon, 25 Aug 2025 19:31:53 +0200 Subject: Get nearest power of 2 for max file count before checking against current count --- src/SFileCompactArchive.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/SFileCompactArchive.cpp') diff --git a/src/SFileCompactArchive.cpp b/src/SFileCompactArchive.cpp index 8ad1b4b..63a6de2 100644 --- a/src/SFileCompactArchive.cpp +++ b/src/SFileCompactArchive.cpp @@ -463,15 +463,17 @@ DWORD WINAPI SFileGetMaxFileCount(HANDLE hMpq) bool WINAPI SFileSetMaxFileCount(HANDLE hMpq, DWORD dwMaxFileCount) { TMPQArchive * ha = (TMPQArchive *)hMpq; - DWORD dwNewHashTableSize = 0; DWORD dwErrCode = ERROR_SUCCESS; + // Calculate the hash table size for the new file limit + DWORD dwNewHashTableSize = GetNearestPowerOfTwo(dwMaxFileCount); + // Test the valid parameters if(!IsValidMpqHandle(hMpq)) dwErrCode = ERROR_INVALID_HANDLE; if(ha->dwFlags & MPQ_FLAG_READ_ONLY) dwErrCode = ERROR_ACCESS_DENIED; - if(dwMaxFileCount < ha->dwFileTableSize) + if(dwNewHashTableSize < ha->dwFileTableSize) dwErrCode = ERROR_DISK_FULL; // ALL file names must be known in order to be able to rebuild hash table @@ -480,9 +482,6 @@ bool WINAPI SFileSetMaxFileCount(HANDLE hMpq, DWORD dwMaxFileCount) dwErrCode = CheckIfAllFilesKnown(ha); if(dwErrCode == ERROR_SUCCESS) { - // Calculate the hash table size for the new file limit - dwNewHashTableSize = GetNearestPowerOfTwo(dwMaxFileCount); - // Rebuild both file tables dwErrCode = RebuildFileTable(ha, dwNewHashTableSize); } -- cgit v1.2.3