From c3a2a31b02475061770f2a04e84229811823b942 Mon Sep 17 00:00:00 2001 From: Fabian Fichter Date: Sat, 10 Dec 2022 18:21:40 +0100 Subject: [PATCH] Fix variant parsing for invalid board size --- src/parser.cpp | 4 ++-- src/variant.h | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/parser.cpp b/src/parser.cpp index eda6346..196cfca 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -378,8 +378,6 @@ Variant* VariantParser::parse(Variant* v) { parse_attribute("materialCounting", v->materialCounting); parse_attribute("countingRule", v->countingRule); - v->conclude(); // In preparation for the consistency checks below, in case conclude() hasn't been called yet. - // Report invalid options if (DoCheck) { @@ -399,6 +397,8 @@ Variant* VariantParser::parse(Variant* v) { std::cerr << piece_name(pt) << " - Ambiguous piece character: " << v->pieceToChar[make_piece(c, pt)] << std::endl; } + v->conclude(); // In preparation for the consistency checks below + // startFen if (FEN::validate_fen(v->startFen, v, v->chess960) != FEN::FEN_OK) std::cerr << "startFen - Invalid starting position: " << v->startFen << std::endl; diff --git a/src/variant.h b/src/variant.h index a54e541..d76e908 100644 --- a/src/variant.h +++ b/src/variant.h @@ -240,8 +240,10 @@ struct Variant { // Map king squares to enumeration of actually available squares. // E.g., for xiangqi map from 0-89 to 0-8. // Variants might be initialized before bitboards, so do not rely on precomputed bitboards (like SquareBB). + // Furthermore conclude() might be called on invalid configuration during validation, + // therefore skip proper initialization in case of invalid board size. int nnueKingSquare = 0; - if (nnueKing) + if (nnueKing && nnueSquares <= SQUARE_NB) for (Square s = SQ_A1; s < nnueSquares; ++s) { Square bitboardSquare = Square(s + s / (maxFile + 1) * (FILE_MAX - maxFile)); -- 1.7.0.4