Prevent out-of-bound array accesses
authorFabian Fichter <ianfab@users.noreply.github.com>
Fri, 16 Aug 2019 17:09:19 +0000 (19:09 +0200)
committerFabian Fichter <ianfab@users.noreply.github.com>
Fri, 16 Aug 2019 17:09:19 +0000 (19:09 +0200)
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
src/search.cpp

index e26f75a..86dc11c 100644 (file)
@@ -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
index c269024..94dec65 100644 (file)
@@ -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;