]> git.sesse.net Git - stockfish/commitdiff
Fix wrong assert.
authorJoost VandeVondele <Joost.VandeVondele@gmail.com>
Fri, 7 Feb 2020 09:42:10 +0000 (10:42 +0100)
committerJoost VandeVondele <Joost.VandeVondele@gmail.com>
Mon, 10 Feb 2020 08:12:07 +0000 (09:12 +0100)
can trigger an abort when compiling with debug=yes, and using 7men TB.
The assert should check that less than 8 pieces are in the key for each
side, matching the assumption that underlies the FEN string construction.
Also take explicitly care of a 'v' character in material strings.

Fixes an issue reported in the forum:
https://groups.google.com/d/msg/fishcooking/yoVC7etIpz0/7mS7ntZMBAAJ

closes https://github.com/official-stockfish/Stockfish/pull/2547

No functional change.

src/position.cpp

index 5efd9c42a5eb351df1c043ea0b1e25a84b28f935..0ac450570b91b28ac468373995b42033ef0f3164 100644 (file)
@@ -375,11 +375,13 @@ void Position::set_state(StateInfo* si) const {
 
 Position& Position::set(const string& code, Color c, StateInfo* si) {
 
 
 Position& Position::set(const string& code, Color c, StateInfo* si) {
 
-  assert(code.length() > 0 && code.length() < 8);
   assert(code[0] == 'K');
 
   string sides[] = { code.substr(code.find('K', 1)),      // Weak
   assert(code[0] == 'K');
 
   string sides[] = { code.substr(code.find('K', 1)),      // Weak
-                     code.substr(0, code.find('K', 1)) }; // Strong
+                     code.substr(0, std::min(code.find('v'), code.find('K', 1))) }; // Strong
+
+  assert(sides[0].length() > 0 && sides[0].length() < 8);
+  assert(sides[1].length() > 0 && sides[1].length() < 8);
 
   std::transform(sides[c].begin(), sides[c].end(), sides[c].begin(), tolower);
 
 
   std::transform(sides[c].begin(), sides[c].end(), sides[c].begin(), tolower);