From 6b4cbbd1629b58013eb107120ce1a04ef41d47c1 Mon Sep 17 00:00:00 2001 From: Eyal Ben-David Date: Tue, 19 Aug 2025 01:51:57 +0300 Subject: [PATCH] bitboard.h: check for invalid square at isAttackedBy() This commit Fixes the following crash scenario: In Menus: Click Edit | Setup Position... Click Clear Click on White King CRASH This commit checks in advance for InvalidSquare in function is AttackedBy(). The crash was: If a King is removed its square is set to InvalidSquare, Later when checking if that square is attacked we have a crash of accessing index beyond the board size. --- src/database/bitboard.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/database/bitboard.h b/src/database/bitboard.h index 8c0baa36..b993c5d0 100644 --- a/src/database/bitboard.h +++ b/src/database/bitboard.h @@ -378,6 +378,10 @@ const unsigned int bb_ShiftL45[64] = inline bool BitBoard::isAttackedBy(const unsigned int color, chessx::Square square) const { + if(square == chessx::InvalidSquare) + { + return 0; + } if(bb_PawnAttacks[color ^ 1][square] & m_pawns & m_occupied_co[color]) { return 1;