mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-21 17:46:26 +08:00
Fix a possible overflow in TT resize
On platforms where size_t is 32 bit, we can have an overflow in this expression: (mbSize * 1024 * 1024) Fix it setting max hash size of 2GB on platforms where size_t is 32 bit. A small rename while there: now struct Cluster is definied inside class TranspositionTable so we should drop the redundant TT prefix. No functional change.
This commit is contained in:
10
src/tt.cpp
10
src/tt.cpp
@@ -32,9 +32,9 @@ TranspositionTable TT; // Our global transposition table
|
||||
|
||||
void TranspositionTable::resize(size_t mbSize) {
|
||||
|
||||
assert(sizeof(TTCluster) == CacheLineSize / 2);
|
||||
assert(sizeof(Cluster) == CacheLineSize / 2);
|
||||
|
||||
size_t newClusterCount = size_t(1) << msb((mbSize * 1024 * 1024) / sizeof(TTCluster));
|
||||
size_t newClusterCount = size_t(1) << msb((mbSize * 1024 * 1024) / sizeof(Cluster));
|
||||
|
||||
if (newClusterCount == clusterCount)
|
||||
return;
|
||||
@@ -42,7 +42,7 @@ void TranspositionTable::resize(size_t mbSize) {
|
||||
clusterCount = newClusterCount;
|
||||
|
||||
free(mem);
|
||||
mem = calloc(clusterCount * sizeof(TTCluster) + CacheLineSize - 1, 1);
|
||||
mem = calloc(clusterCount * sizeof(Cluster) + CacheLineSize - 1, 1);
|
||||
|
||||
if (!mem)
|
||||
{
|
||||
@@ -51,7 +51,7 @@ void TranspositionTable::resize(size_t mbSize) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
table = (TTCluster*)((uintptr_t(mem) + CacheLineSize - 1) & ~(CacheLineSize - 1));
|
||||
table = (Cluster*)((uintptr_t(mem) + CacheLineSize - 1) & ~(CacheLineSize - 1));
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ void TranspositionTable::resize(size_t mbSize) {
|
||||
|
||||
void TranspositionTable::clear() {
|
||||
|
||||
std::memset(table, 0, clusterCount * sizeof(TTCluster));
|
||||
std::memset(table, 0, clusterCount * sizeof(Cluster));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user