Fix undefined behavior

C++ standard does not define `uint8_t` as an allowed pointer alias type. Despite
`uint8_t` being `unsigned char` on most platforms, this is not enforced by the standard.

https://eel.is/c++draft/basic.lval#11
https://stackoverflow.com/a/16138470

closes https://github.com/official-stockfish/Stockfish/pull/6420

No functional change
This commit is contained in:
Shawn Xu
2025-11-14 17:43:44 +01:00
committed by Joost VandeVondele
parent 4b71d8e202
commit 1d504b927f
+2 -3
View File
@@ -77,10 +77,9 @@ struct AccumulatorCaches {
// To initialize a refresh entry, we set all its bitboards empty,
// so we put the biases in the accumulation, without any weights on top
void clear(const std::array<BiasType, Size>& biases) {
accumulation = biases;
std::memset((uint8_t*) this + offsetof(Entry, psqtAccumulation), 0,
sizeof(Entry) - offsetof(Entry, psqtAccumulation));
std::memset(reinterpret_cast<std::byte*>(this) + offsetof(Entry, psqtAccumulation),
0, sizeof(Entry) - offsetof(Entry, psqtAccumulation));
}
};