]> git.sesse.net Git - stockfish/commitdiff
Validate input UCI moves
authorMarco Costalba <mcostalba@gmail.com>
Sun, 17 Jul 2011 09:22:08 +0000 (10:22 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sun, 17 Jul 2011 09:22:55 +0000 (10:22 +0100)
Running following command:

  position startpos moves e1e8

Makes SF to assert in debug mode in do_move() but to accept
bad input and continue in release mode where probably it is
going to crash little later.

So validate input before to feed do_move().

Suggestion by Yakovlev Vadim.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/position.cpp
src/uci.cpp

index 18f4978da197241f5ab3d437e56c123cd2c58bbb..abe24a52404ccfb053303928c831084c9d990bb2 100644 (file)
@@ -777,6 +777,8 @@ bool Position::move_gives_check(Move m, const CheckInfo& ci) const {
 
 void Position::do_setup_move(Move m) {
 
+  assert(move_is_ok(m));
+
   StateInfo newSt;
 
   // Update the number of full moves after black's move
index cc3a271d6f201af8210e4d521093443f6a3ed783..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);
   }