mirror of
https://github.com/sockspls/badfish
synced 2025-07-11 11:39:15 +00:00
Constructed objects must be destructible
Pointer members of WDLEntry and DTZEntry must be null, so they can be freed. Whether unmap() behaves like free() and tolerates a NULL pointer (treated as no-op) is unclear. Better safe than sorry, so test data before calling unmap(). Simplify hasUniquePieces calculation while at it. No functional change.
This commit is contained in:
parent
578e94629b
commit
a9abb35c9c
1 changed files with 9 additions and 18 deletions
|
@ -481,7 +481,6 @@ WDLEntry::WDLEntry(const Position& pos, Key keys[])
|
||||||
memset(this, 0, sizeof(WDLEntry));
|
memset(this, 0, sizeof(WDLEntry));
|
||||||
|
|
||||||
key = keys[WHITE];
|
key = keys[WHITE];
|
||||||
ready = 0;
|
|
||||||
num = pos.count<ALL_PIECES>(WHITE) + pos.count<ALL_PIECES>(BLACK);
|
num = pos.count<ALL_PIECES>(WHITE) + pos.count<ALL_PIECES>(BLACK);
|
||||||
symmetric = (keys[WHITE] == keys[BLACK]);
|
symmetric = (keys[WHITE] == keys[BLACK]);
|
||||||
has_pawns = pos.count<PAWN>(WHITE) + pos.count<PAWN>(BLACK);
|
has_pawns = pos.count<PAWN>(WHITE) + pos.count<PAWN>(BLACK);
|
||||||
|
@ -494,26 +493,17 @@ WDLEntry::WDLEntry(const Position& pos, Key keys[])
|
||||||
|
|
||||||
pawn.pawns[0] = pos.count<PAWN>(c ? WHITE : BLACK);
|
pawn.pawns[0] = pos.count<PAWN>(c ? WHITE : BLACK);
|
||||||
pawn.pawns[1] = pos.count<PAWN>(c ? BLACK : WHITE);
|
pawn.pawns[1] = pos.count<PAWN>(c ? BLACK : WHITE);
|
||||||
} else {
|
} else
|
||||||
int uniquePieces = 0;
|
for (Color c = WHITE; c <= BLACK; ++c)
|
||||||
|
for (PieceType pt = PAWN; pt < KING; ++pt)
|
||||||
for (PieceType pt = PAWN; pt <= KING; ++pt)
|
if (popcount(pos.pieces(c, pt)) == 1)
|
||||||
uniquePieces += (popcount(pos.pieces(WHITE, pt)) == 1)
|
piece.hasUniquePieces = true;
|
||||||
+ (popcount(pos.pieces(BLACK, pt)) == 1);
|
|
||||||
|
|
||||||
if (uniquePieces >= 3)
|
|
||||||
piece.hasUniquePieces = 1;
|
|
||||||
else {
|
|
||||||
// No unique pieces, other than W_KING and B_KING
|
|
||||||
assert(uniquePieces == 2);
|
|
||||||
piece.hasUniquePieces = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WDLEntry::~WDLEntry()
|
WDLEntry::~WDLEntry()
|
||||||
{
|
{
|
||||||
TBFile::unmap(baseAddress, mapping);
|
if (baseAddress)
|
||||||
|
TBFile::unmap(baseAddress, mapping);
|
||||||
|
|
||||||
if (has_pawns)
|
if (has_pawns)
|
||||||
for (File f = FILE_A; f <= FILE_D; ++f) {
|
for (File f = FILE_A; f <= FILE_D; ++f) {
|
||||||
|
@ -546,7 +536,8 @@ DTZEntry::DTZEntry(WDLEntry* wdl, Key k[])
|
||||||
|
|
||||||
DTZEntry::~DTZEntry()
|
DTZEntry::~DTZEntry()
|
||||||
{
|
{
|
||||||
TBFile::unmap(baseAddress, mapping);
|
if (baseAddress)
|
||||||
|
TBFile::unmap(baseAddress, mapping);
|
||||||
|
|
||||||
if (has_pawns)
|
if (has_pawns)
|
||||||
for (File f = FILE_A; f <= FILE_D; ++f)
|
for (File f = FILE_A; f <= FILE_D; ++f)
|
||||||
|
|
Loading…
Add table
Reference in a new issue