From: H.G. Muller Date: Thu, 16 Sep 2010 16:02:40 +0000 (+0200) Subject: Fix silent bug in drop moves X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=e22090f94af45d13d5e735e3227ff4573e62654e;p=xboard.git Fix silent bug in drop moves In ApplyMove() the piece on the from square was accessed and used before we tested for drop moves. As drop moves have off-board from-squares this led to out-of-bound array access, which apparently was usually harmless. --- diff --git a/backend.c b/backend.c index b124be6..b269cde 100644 --- a/backend.c +++ b/backend.c @@ -8324,7 +8324,6 @@ ApplyMove(fromX, fromY, toX, toY, promoChar, board) /* [HGM] compute & store e.p. status and castling rights for new position */ /* we can always do that 'in place', now pointers to these rights are passed to ApplyMove */ - { int i; if(gameInfo.variant == VariantBerolina) berolina = EP_BEROLIN_A; oldEP = (signed char)board[EP_STATUS]; @@ -8333,6 +8332,16 @@ ApplyMove(fromX, fromY, toX, toY, promoChar, board) if( board[toY][toX] != EmptySquare ) board[EP_STATUS] = EP_CAPTURE; + /* [HGM] In Shatranj and Courier all promotions are to Ferz */ + if((gameInfo.variant==VariantShatranj || gameInfo.variant==VariantCourier || gameInfo.variant == VariantMakruk) + && promoChar != 0) promoChar = PieceToChar(WhiteFerz); + + if (fromY == DROP_RANK) { + /* must be first */ + piece = board[toY][toX] = (ChessSquare) fromX; + } else { + int i; + if( board[fromY][fromX] == WhitePawn ) { if(fromY != toY) // [HGM] Xiangqi sideway Pawn moves should not count as 50-move breakers board[EP_STATUS] = EP_PAWN_MOVE; @@ -8364,18 +8373,8 @@ ApplyMove(fromX, fromY, toX, toY, promoChar, board) ) board[CASTLING][i] = NoRights; // revoke for moved or captured piece } - } + if (fromX == toX && fromY == toY) return; - /* [HGM] In Shatranj and Courier all promotions are to Ferz */ - if((gameInfo.variant==VariantShatranj || gameInfo.variant==VariantCourier || gameInfo.variant == VariantMakruk) - && promoChar != 0) promoChar = PieceToChar(WhiteFerz); - - if (fromX == toX && fromY == toY) return; - - if (fromY == DROP_RANK) { - /* must be first */ - piece = board[toY][toX] = (ChessSquare) fromX; - } else { piece = board[fromY][fromX]; /* [HGM] remember, for Shogi promotion */ king = piece < (int) BlackPawn ? WhiteKing : BlackKing; /* [HGM] Knightmate simplify testing for castling */ if(gameInfo.variant == VariantKnightmate)