Skip to content

Commit faf542a

Browse files
committed
Avoid undefined behaviour for geometries as a1b1 [defect]
Reported by Rasmus A. using CodeSonar, appreciated! This not only fixes potential undefined behaviour, but the old code worked by accident anyway for the other geometries (wrapping from rank8 to rank1 didn't cause any harm but was unintended...)
1 parent e9b0977 commit faf542a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

kpk.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ int kpkGenerate(void)
118118

119119
// Valid positions after black move, pawn capture allowed
120120
valid[ix] = ~allKing(bit(wKing));
121-
if (file(wPawn) != fileA) valid[ix] &= ~bit(wPawn+N+W);
122-
if (file(wPawn) != fileH) valid[ix] &= ~bit(wPawn+N+E);
121+
if (rank(wPawn) != rank8 && file(wPawn) != fileA) valid[ix] &= ~bit(wPawn+N+W);
122+
if (rank(wPawn) != rank8 && file(wPawn) != fileH) valid[ix] &= ~bit(wPawn+N+E);
123123
}
124124

125125
int changed;

0 commit comments

Comments
 (0)