From 7bd56aa63088635560b3e4c854a8dfdbff5af688 Mon Sep 17 00:00:00 2001 From: Fabian Fichter Date: Fri, 16 Aug 2019 19:09:19 +0200 Subject: [PATCH] Prevent out-of-bound array accesses Squares outside of board were used in following scenarios: - Passed pawn evaluation of unpromoted pawns on last rank (e.g., in sittuyin) - SEE pruning of check evading drops in qsearch --- src/pawns.cpp | 2 +- src/search.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pawns.cpp b/src/pawns.cpp index e26f75a..86dc11c 100644 --- a/src/pawns.cpp +++ b/src/pawns.cpp @@ -124,7 +124,7 @@ namespace { // Passed pawns will be properly scored later in evaluation when we have // full attack info. - if (passed) + if (passed && is_ok(s + Up)) e->passedPawns[Us] |= s; // Score this pawn diff --git a/src/search.cpp b/src/search.cpp index c269024..94dec65 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -1497,7 +1497,7 @@ moves_loop: // When in check, search starts from here // Don't search moves with negative SEE values if ( (!inCheck || evasionPrunable) - && (!givesCheck || !(pos.blockers_for_king(~pos.side_to_move()) & from_sq(move))) + && (!givesCheck || !(is_ok(from_sq(move)) && pos.blockers_for_king(~pos.side_to_move()) & from_sq(move))) && !pos.see_ge(move)) continue; -- 1.7.0.4