diff options
Diffstat (limited to 'src/bitboard.c')
| -rwxr-xr-x | src/bitboard.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/bitboard.c b/src/bitboard.c index 0478fc1..9e9df48 100755 --- a/src/bitboard.c +++ b/src/bitboard.c @@ -389,10 +389,21 @@ Return value: { ASSERT(*pbb); uLastBit--; - *pbb &= (*pbb - 1); c = BIT_NUMBER_TO_COOR(uLastBit); ASSERT(c == SLOW_BIT_NUMBER_TO_COOR(uLastBit)); ASSERT(IS_ON_BOARD(c)); + // BUG (fixed): this used to be `*pbb &= (*pbb - 1)`, which + // clears the LOWEST set bit -- correct for + // CoorFromBitBoardRank8ToRank1's first-bit semantics, wrong + // here, where uLastBit is the HIGHEST set bit. With more than + // one bit set (e.g. doubled pawns on a file), that cleared the + // wrong bit: the reported (highest) bit was never actually + // removed, so a caller looping on this function would see it + // again next call (a duplicate) while the true lowest bit was + // silently skipped forever. Single-bit inputs never exposed + // this (lowest-bit-clear and highest-bit-clear coincide when + // there's only one bit). + *pbb &= ~COOR_TO_BB(c); } return(c); } |
