mirror of
https://github.com/official-stockfish/Stockfish.git
synced 2026-07-22 12:47:08 +00:00
Fix FEN validation of pawns on first or eighth rank
The FEN validation check intended to reject pawns on the first or eighth rank uses the `Rank` enum values in a bitwise OR operation: `if (pieces(PAWN) & (RANK_1 | RANK_8))` `RANK_1 | RANK_8` evaluates to the integer `0 | 7 == 7` instead of a bitboard, so the expression only tests squares A1, B1 and C1. As a result, unsupported positions with pawns elsewhere on the first or eighth rank are silently accepted. For instance, `position fen 3P3k/8/8/8/8/8/8/3K4 w - - 0 1` is accepted even though the pawn on d8 makes the position unsupported. Use the `Rank1BB | Rank8BB` bitboard constants so any pawn on the first or eighth rank are correctly rejected. closes https://github.com/official-stockfish/Stockfish/pull/6887 No functional change
This commit is contained in:
committed by
Joost VandeVondele
parent
7b37032885
commit
5595cb20ea
@@ -198,6 +198,7 @@ Nour Berakdar (Nonlinear)
|
||||
Ofek Shochat (OfekShochat, ghostway)
|
||||
Ondrej Mosnáček (WOnder93)
|
||||
Ondřej Mišina (AndrovT)
|
||||
Onur Zungur (zungur)
|
||||
Oskar Werkelin Ahlin
|
||||
Ömer Faruk Tutkun (OmerFarukTutkun)
|
||||
Pablo Vazquez
|
||||
|
||||
+1
-1
@@ -270,7 +270,7 @@ Position::set(const string& fenStr, bool isChess960, StateInfo* si) {
|
||||
if (rank != RANK_1 || file != FILE_NB)
|
||||
return PositionSetError("Invalid FEN. Board state encoding ended but cursor not at end.");
|
||||
|
||||
if (pieces(PAWN) & (RANK_1 | RANK_8))
|
||||
if (pieces(PAWN) & (Rank1BB | Rank8BB))
|
||||
return PositionSetError("Unsupported position. Pawns on the first or eighth rank.");
|
||||
|
||||
if (count<KING>(WHITE) != 1 || count<KING>(BLACK) != 1)
|
||||
|
||||
Reference in New Issue
Block a user