mirror of
https://github.com/official-stockfish/Stockfish.git
synced 2026-07-22 12:47:08 +00:00
Fix integer overflow.
scaledBonus can reach rather large values, which lead to an int overflow as detected anematode using ubsan. (see https://github.com/official-stockfish/Stockfish/issues/6505#issuecomment-3696988889) It can be fixed by scaling nominator and denominator appropriately, which doesn't change the bench, as long as there is no overflow. First overflow/bench change happens at depth 26 closes https://github.com/official-stockfish/Stockfish/pull/6540 Bench: 2050811
This commit is contained in:
+2
-2
@@ -1432,6 +1432,7 @@ moves_loop: // When in check, search starts here
|
|||||||
|
|
||||||
bonusScale = std::max(bonusScale, 0);
|
bonusScale = std::max(bonusScale, 0);
|
||||||
|
|
||||||
|
// scaledBonus ranges from 0 to roughly 2.3M, overflows happen for multipliers larger than 900
|
||||||
const int scaledBonus = std::min(141 * depth - 87, 1351) * bonusScale;
|
const int scaledBonus = std::min(141 * depth - 87, 1351) * bonusScale;
|
||||||
|
|
||||||
update_continuation_histories(ss - 1, pos.piece_on(prevSq), prevSq,
|
update_continuation_histories(ss - 1, pos.piece_on(prevSq), prevSq,
|
||||||
@@ -1440,8 +1441,7 @@ moves_loop: // When in check, search starts here
|
|||||||
mainHistory[~us][((ss - 1)->currentMove).raw()] << scaledBonus * 243 / 32768;
|
mainHistory[~us][((ss - 1)->currentMove).raw()] << scaledBonus * 243 / 32768;
|
||||||
|
|
||||||
if (type_of(pos.piece_on(prevSq)) != PAWN && ((ss - 1)->currentMove).type_of() != PROMOTION)
|
if (type_of(pos.piece_on(prevSq)) != PAWN && ((ss - 1)->currentMove).type_of() != PROMOTION)
|
||||||
sharedHistory.pawn_entry(pos)[pos.piece_on(prevSq)][prevSq]
|
sharedHistory.pawn_entry(pos)[pos.piece_on(prevSq)][prevSq] << scaledBonus * 290 / 8192;
|
||||||
<< scaledBonus * 1160 / 32768;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bonus for prior capture countermove that caused the fail low
|
// Bonus for prior capture countermove that caused the fail low
|
||||||
|
|||||||
Reference in New Issue
Block a user