diff --git a/src/bitboard.h b/src/bitboard.h index c3130b4c..3476924c 100644 --- a/src/bitboard.h +++ b/src/bitboard.h @@ -63,7 +63,9 @@ extern Bitboard StarSquareBB12; inline Bitboard square_bb(Square s) { - assert(SQ_BEGIN <= s && s < SQ_END); + if (!(SQ_BEGIN <= s && s < SQ_END)) + return 0; + return SquareBB[s]; } diff --git a/src/misc.cpp b/src/misc.cpp index 88256411..df9f1f4f 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -545,6 +545,8 @@ int best_group(size_t idx) // Early exit if the needed API is not available at runtime HMODULE k32 = GetModuleHandle(L"Kernel32.dll"); + if (k32 == nullptr) + return -1; auto fun1 = (fun1_t)(void(*)())GetProcAddress(k32, "GetLogicalProcessorInformationEx"); if (!fun1) return -1; @@ -557,6 +559,9 @@ int best_group(size_t idx) SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *buffer, *ptr; ptr = buffer = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *)malloc(returnLength); + if (ptr == nullptr) + return -1; + // Second call, now we expect to succeed if (!fun1(RelationAll, buffer, &returnLength)) { free(buffer); @@ -611,6 +616,8 @@ void bindThisThread(size_t idx) // Early exit if the needed API are not available at runtime HMODULE k32 = GetModuleHandle(L"Kernel32.dll"); + if (k32 == nullptr) + return; auto fun2 = (fun2_t)(void(*)())GetProcAddress(k32, "GetNumaNodeProcessorMaskEx"); auto fun3 = (fun3_t)(void(*)())GetProcAddress(k32, "SetThreadGroupAffinity"); diff --git a/src/position.cpp b/src/position.cpp index e901035a..094987cc 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -1083,7 +1083,7 @@ int Position::potential_mills_count(Square to, Color c, Square from) c = color_on(to); } - if (from != SQ_0) { + if (from != SQ_0 && from >= SQ_BEGIN && from < SQ_END) { locbak = board[from]; board[from] = NO_PIECE; @@ -1101,7 +1101,7 @@ int Position::potential_mills_count(Square to, Color c, Square from) } } - if (from != SQ_0) { + if (from != SQ_0 && from >= SQ_BEGIN && from < SQ_END) { board[from] = locbak; SET_BIT(byTypeBB[ALL_PIECES], from);