From d57b58849bda868f2463d38cc636f01af919316c Mon Sep 17 00:00:00 2001 From: Shauren Date: Tue, 5 Sep 2023 00:10:35 +0200 Subject: Dep/CascLib: Update to ladislav-zezula/CascLib@5c60050770767f2e606f6fec0c35beb8b9b00c60 --- dep/CascLib/src/common/Map.h | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'dep/CascLib/src/common/Map.h') diff --git a/dep/CascLib/src/common/Map.h b/dep/CascLib/src/common/Map.h index 54dda5baed8..68177c466fc 100644 --- a/dep/CascLib/src/common/Map.h +++ b/dep/CascLib/src/common/Map.h @@ -15,7 +15,6 @@ // Structures #define MIN_HASH_TABLE_SIZE 0x00000100 // The smallest size of the hash table. -#define MAX_HASH_TABLE_SIZE 0x00800000 // The largest size of the hash table. Should be enough for any game. typedef int (*PFNCOMPAREFUNC)(const void * pvObjectKey, const void * pvKey, size_t nKeyLength); typedef DWORD (*PFNHASHFUNC)(void * pvKey, size_t nKeyLength); @@ -36,7 +35,7 @@ typedef enum _KEY_TYPE inline DWORD CalcHashValue_Hash(void * pvKey, size_t /* nKeyLength */) { // Get the hash directly as value - return ConvertBytesToInteger_4((LPBYTE)pvKey); + return ConvertBytesToInteger_4_LE((LPBYTE)pvKey); } // Calculates hash value from a key @@ -328,20 +327,22 @@ class CASC_MAP size_t GetNearestPowerOfTwo(size_t MaxItems) { - size_t PowerOfTwo; + size_t PowerOfTwo = MIN_HASH_TABLE_SIZE; // Round the hash table size up to the nearest power of two - for(PowerOfTwo = MIN_HASH_TABLE_SIZE; PowerOfTwo <= MAX_HASH_TABLE_SIZE; PowerOfTwo <<= 1) + while(PowerOfTwo < MaxItems) { - if(PowerOfTwo > MaxItems) + // Overflow check + if((PowerOfTwo << 1) < PowerOfTwo) { - return PowerOfTwo; + assert(false); + return 0; } - } - // If the hash table is too big, we cannot create the map - assert(false); - return 0; + // Shift the value + PowerOfTwo <<= 1; + } + return PowerOfTwo; } PFNHASHFUNC PfnCalcHashValue; -- cgit v1.2.3