From 732aa34e3dec39de9c80a07f6ecba7cb0569b95e Mon Sep 17 00:00:00 2001 From: Joost VandeVondele Date: Wed, 17 May 2017 18:15:01 -0700 Subject: [PATCH 1/1] Fix memory access in Search::clear() Fixes a bug in Search::clear, where the filling of CounterMoveStats&, overwrote (currently presumably unused) memory because sizeof(cm) returns the size in bytes, whereas elements was needed. No functional change Closes #1119 --- src/search.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/search.cpp b/src/search.cpp index e8e15ef2..de487e57 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -197,9 +197,10 @@ void Search::clear() { th->history.clear(); th->counterMoveHistory.clear(); th->resetCalls = true; + CounterMoveStats& cm = th->counterMoveHistory[NO_PIECE][0]; - int* t = &cm[NO_PIECE][0]; - std::fill(t, t + sizeof(cm), CounterMovePruneThreshold - 1); + auto* t = &cm[NO_PIECE][0]; + std::fill(t, t + sizeof(cm)/sizeof(*t), CounterMovePruneThreshold - 1); } Threads.main()->previousScore = VALUE_INFINITE; -- 2.39.2