]> git.sesse.net Git - stockfish/blobdiff - src/uci.cpp
Validate input UCI moves
[stockfish] / src / uci.cpp
index 5a302a8d1b9d44286a39be48aeb25bcd69607ec0..673d661878a7b1b12ea687c9f9f9909bc355b227 100644 (file)
@@ -120,6 +120,7 @@ namespace {
 
   void set_position(Position& pos, UCIParser& up) {
 
+    Move m;
     string token, fen;
 
     up >> token; // operator>>() skips any whitespace
@@ -139,8 +140,8 @@ namespace {
     else return;
 
     // Parse move list (if any)
-    while (up >> token)
-        pos.do_setup_move(move_from_uci(pos, token));
+    while (up >> token && (m = move_from_uci(pos, token)) != MOVE_NONE)
+        pos.do_setup_move(m);
   }
 
 
@@ -182,8 +183,7 @@ namespace {
 
     string token;
     SearchLimits limits;
-    Move searchMoves[MAX_MOVES] = { MOVE_NONE };
-    Move* cur = searchMoves;
+    Move searchMoves[MAX_MOVES], *cur = searchMoves;
     int time[] = { 0, 0 }, inc[] = { 0, 0 };
 
     while (up >> token)
@@ -209,16 +209,11 @@ namespace {
         else if (token == "movetime")
             up >> limits.maxTime;
         else if (token == "searchmoves")
-        {
             while (up >> token)
                 *cur++ = move_from_uci(pos, token);
-
-            *cur = MOVE_NONE;
-        }
     }
 
-    assert(pos.is_ok());
-
+    *cur = MOVE_NONE;
     limits.time = time[pos.side_to_move()];
     limits.increment = inc[pos.side_to_move()];
 
@@ -228,7 +223,7 @@ namespace {
 
   // perft() is called when engine receives the "perft" command.
   // The function calls perft() passing the required search depth
-  // then prints counted nodes and elapsed time.
+  // then prints counted leaf nodes and elapsed time.
 
   void perft(Position& pos, UCIParser& up) {