Browse Source

Bugfix: HashTable had an integer overflow when the number of elements was very large

Jorrit Rouwe 8 months ago
parent
commit
e18aa8b300
1 changed files with 1 additions and 1 deletions
  1. 1 1
      Jolt/Core/HashTable.h

+ 1 - 1
Jolt/Core/HashTable.h

@@ -119,7 +119,7 @@ private:
 
 
 		mMaxSize = inMaxSize;
 		mMaxSize = inMaxSize;
 		mMaxLoad = uint32((cMaxLoadFactorNumerator * inMaxSize) / cMaxLoadFactorDenominator);
 		mMaxLoad = uint32((cMaxLoadFactorNumerator * inMaxSize) / cMaxLoadFactorDenominator);
-		size_type required_size = mMaxSize * (sizeof(KeyValue) + 1) + 15; // Add 15 bytes to mirror the first 15 bytes of the control values
+		size_t required_size = size_t(mMaxSize) * (sizeof(KeyValue) + 1) + 15; // Add 15 bytes to mirror the first 15 bytes of the control values
 		if constexpr (cNeedsAlignedAllocate)
 		if constexpr (cNeedsAlignedAllocate)
 			mData = reinterpret_cast<KeyValue *>(AlignedAllocate(required_size, alignof(KeyValue)));
 			mData = reinterpret_cast<KeyValue *>(AlignedAllocate(required_size, alignof(KeyValue)));
 		else
 		else