]> git.sesse.net Git - stockfish/commit
Correct a bug introduced by Stéphane in the previous patch.
authorStéphane Nicolet <cassio@free.fr>
Wed, 2 May 2018 11:20:47 +0000 (13:20 +0200)
committerStéphane Nicolet <cassio@free.fr>
Wed, 2 May 2018 11:38:00 +0000 (13:38 +0200)
commit06e0134cbc9bcf16d01738c491ec53869a5205b6
treea8df0d219d9fa8fe58e601ca51011298b579066f
parent12ef8f71a2822f91e844e26d352d5fc27ac9559f
Correct a bug introduced by Stéphane in the previous patch.

When we are using the "Bitboard + Square" overloaded operators,
the compiler uses the interpediate SquareBB[s] to transform the
square into a Bitboard, and then calculate the result.

For instance, the following code:

```
   b = pos.pieces(Us, PAWN) & s
```

generates in fact the code:

```
   b = pos.pieces(Us, PAWN) & SquareBB[s]`
```

The bug introduced by Stéphane in the previous patch was the
use of `b = pos.pieces(Us, PAWN) & (s + Up)` which can result
in out-of-bounds errors for the SquareBB[] array if s in the
last rank of the board.

We coorect the bug, and also add some asserts in bitboard.h to
make the code more robust for this particular bug in the future.

Bug report by Joost VandeVondele. Thanks!

Bench: 5512000
src/bitboard.h
src/pawns.cpp