From 1d504b927fde7c3227a0c32f26fd49810c0fcd55 Mon Sep 17 00:00:00 2001 From: Shawn Xu Date: Thu, 13 Nov 2025 20:57:58 -0800 Subject: [PATCH] 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 --- src/nnue/nnue_accumulator.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/nnue/nnue_accumulator.h b/src/nnue/nnue_accumulator.h index 341960b30..c0a912f58 100644 --- a/src/nnue/nnue_accumulator.h +++ b/src/nnue/nnue_accumulator.h @@ -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& biases) { - accumulation = biases; - std::memset((uint8_t*) this + offsetof(Entry, psqtAccumulation), 0, - sizeof(Entry) - offsetof(Entry, psqtAccumulation)); + std::memset(reinterpret_cast(this) + offsetof(Entry, psqtAccumulation), + 0, sizeof(Entry) - offsetof(Entry, psqtAccumulation)); } };