From: Marco Costalba Date: Tue, 6 Oct 2009 08:10:42 +0000 (+0200) Subject: Fix use of an initialized SearchStack X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=da948cc94ebef4988199c90389a5099b087d2088 Fix use of an initialized SearchStack In RootMoveList c'tor we allocate a search stack and then call directly qsearch. There is called init_node() that clears all the fields of the search stack array that refers to current ply but not the the killer moves. The killer moves cleared correspond to ply+2. In id_loop() this is not a problem because killer moves of corresponding ply are cleared anyway few instructions later, but in RootMoveList c'tor we leave them uninitialized. This patch fixes this very old bug. It comes direclty from Glaurung age. Bug spotted by Valgrind. Signed-off-by: Marco Costalba --- diff --git a/src/search.cpp b/src/search.cpp index 32934393..17a1aeab 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -299,6 +299,7 @@ namespace { void ponderhit(); void print_current_line(SearchStack ss[], int ply, int threadID); void wait_for_stop_or_ponderhit(); + void init_ss_array(SearchStack ss[]); void idle_loop(int threadID, SplitPoint* waitSp); void init_split_point_stack(); @@ -636,11 +637,7 @@ namespace { // Initialize TT.new_search(); H.clear(); - for (int i = 0; i < 3; i++) - { - ss[i].init(i); - ss[i].initKillers(); - } + init_ss_array(ss); IterationInfo[1] = IterationInfoType(rml.get_move_score(0), rml.get_move_score(0)); Iteration = 1; @@ -1961,6 +1958,7 @@ namespace { // Find a quick score for the move StateInfo st; SearchStack ss[PLY_MAX_PLUS_2]; + init_ss_array(ss); moves[count].move = cur->move; pos.do_move(moves[count].move, st); @@ -2560,6 +2558,18 @@ namespace { } + // init_ss_array() does a fast reset of the first entries of a SearchStack array + + void init_ss_array(SearchStack ss[]) { + + for (int i = 0; i < 3; i++) + { + ss[i].init(i); + ss[i].initKillers(); + } + } + + // wait_for_stop_or_ponderhit() is called when the maximum depth is reached // while the program is pondering. The point is to work around a wrinkle in // the UCI protocol: When pondering, the engine is not allowed to give a