Skip to content

Commit 1d504b9

Browse files
xu-shawnvondele
authored andcommitted
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 #6420 No functional change
1 parent 4b71d8e commit 1d504b9

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/nnue/nnue_accumulator.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,9 @@ struct AccumulatorCaches {
7777
// To initialize a refresh entry, we set all its bitboards empty,
7878
// so we put the biases in the accumulation, without any weights on top
7979
void clear(const std::array<BiasType, Size>& biases) {
80-
8180
accumulation = biases;
82-
std::memset((uint8_t*) this + offsetof(Entry, psqtAccumulation), 0,
83-
sizeof(Entry) - offsetof(Entry, psqtAccumulation));
81+
std::memset(reinterpret_cast<std::byte*>(this) + offsetof(Entry, psqtAccumulation),
82+
0, sizeof(Entry) - offsetof(Entry, psqtAccumulation));
8483
}
8584
};
8685

0 commit comments

Comments
 (0)