From: Fabian Fichter Date: Sat, 29 Feb 2020 22:46:01 +0000 (+0100) Subject: Fix race condition in holding command X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=16ca80a9ad38bfbcfba667c64e610bdf6aecd4ab;p=fairystockfish.git Fix race condition in holding command Prevent race conditions in bughouse by updating the holdings with the captured piece instead of completely overriding them, given that the GUI provides this optional information. Closes #73. --- diff --git a/src/xboard.cpp b/src/xboard.cpp index 69e7252..80bd7df 100644 --- a/src/xboard.cpp +++ b/src/xboard.cpp @@ -259,8 +259,19 @@ void StateMachine::process_command(Position& pos, std::string token, std::istrin if ( std::getline(is, token, '[') && std::getline(is, white_holdings, ']') && std::getline(is, token, '[') && std::getline(is, black_holdings, ']')) { - std::transform(black_holdings.begin(), black_holdings.end(), black_holdings.begin(), ::tolower); - std::string fen = pos.fen(false, false, white_holdings + black_holdings); + std::string fen; + char color, pieceType; + // Use the obtained holding if available to avoid race conditions + if (is >> color && is >> pieceType) + { + fen = pos.fen(); + fen.insert(fen.find(']'), 1, toupper(color) == 'B' ? tolower(pieceType) : toupper(pieceType)); + } + else + { + std::transform(black_holdings.begin(), black_holdings.end(), black_holdings.begin(), ::tolower); + fen = pos.fen(false, false, white_holdings + black_holdings); + } setboard(pos, states, fen); } // restart search