Skip to content

Commit d871ef7

Browse files
committed
policies: fix overflow in calc_factor
Problem: issue #1129 reported `EOVERFLOW` errors for match requests for thousands of CPUs and GPUs. Currently, `calc_factor` computes the tie breaking factor with modular arithmetic. The computation returns -1 when `break_tie` is divisible by `m_multiply_by`. The negative value of `tie` causes the following integer check to overflow, generating a spurious `EOVERFLOW` errno. Fix the computation to ensure `tie` is strictly positive with `abs()`.
1 parent f5f99c5 commit d871ef7

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

resource/policies/dfu_match_multilevel_id_impl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ int64_t multilevel_id_t<FOLD>::score_factor_t::calc_factor (
5555
return -1;
5656
}
5757
mul = add * m_multiply_by;
58-
tie = break_tie % m_multiply_by - 1;
58+
tie = abs (break_tie % static_cast<int64_t> (m_multiply_by) - 1);
5959

6060
if (mul > (std::numeric_limits<int64_t>::max () - tie)) {
6161
errno = EOVERFLOW;

0 commit comments

Comments
 (0)