]> git.sesse.net Git - stockfish/commitdiff
Fix a crash when 'go' multiple times
authorMarco Costalba <mcostalba@gmail.com>
Sat, 1 Jun 2013 13:45:46 +0000 (15:45 +0200)
committerMarco Costalba <mcostalba@gmail.com>
Sat, 1 Jun 2013 14:19:42 +0000 (16:19 +0200)
Search is started after setting a position and
issuing UCI 'go' command. Then if we stop the search
and call 'go' again without setting a new position it
is assumed that the previous setup is preserved, but
this is not the case because what happens is that
SetupStates is reset to NULL, leading to a crash as
soon as RootPos.is_draw() is called because st->previous
is now stale.

UCI protocol is not very clear about requiring that a
position is setup always before launching a search,
so here we easy the life of GUI developers assuming
that the current state is preserved after returning
from a 'stop' command.

Bug reported by Gregor Cramer.

No functional change.

src/thread.cpp

index 782cf1acc0dd5153fb8ba3bebad8cf69bc35da12..b7bead9ff0c867627105cb0eb8ee9ffa328c733e 100644 (file)
@@ -366,10 +366,14 @@ void ThreadPool::start_thinking(const Position& pos, const LimitsType& limits,
   Signals.stopOnPonderhit = Signals.firstRootMove = false;
   Signals.stop = Signals.failedLowAtRoot = false;
 
+  RootMoves.clear();
   RootPos = pos;
   Limits = limits;
-  SetupStates = states; // Ownership transfer here
-  RootMoves.clear();
+  if (states.get()) // If we don't set a new position, preserve current state
+  {
+      SetupStates = states; // Ownership transfer here
+      assert(!states.get());
+  }
 
   for (MoveList<LEGAL> it(pos); *it; ++it)
       if (   searchMoves.empty()