]> git.sesse.net Git - stockfish/commitdiff
Fix use of an initialized SearchStack
authorMarco Costalba <mcostalba@gmail.com>
Tue, 6 Oct 2009 08:10:42 +0000 (10:10 +0200)
committerMarco Costalba <mcostalba@gmail.com>
Tue, 6 Oct 2009 10:12:41 +0000 (11:12 +0100)
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 <mcostalba@gmail.com>
src/search.cpp

index 32934393cbb1e978dd4daedddb9fb5ddd19a44eb..17a1aeab984884b261c08bd858556bcdb8884614 100644 (file)
@@ -299,6 +299,7 @@ namespace {
   void ponderhit();
   void print_current_line(SearchStack ss[], int ply, int threadID);
   void wait_for_stop_or_ponderhit();
   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();
 
   void idle_loop(int threadID, SplitPoint* waitSp);
   void init_split_point_stack();
@@ -636,11 +637,7 @@ namespace {
     // Initialize
     TT.new_search();
     H.clear();
     // 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;
 
     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];
         // 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);
 
         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
   // 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