Skip to content

Commit

Permalink
policies: fix overflow in calc_factor
Browse files Browse the repository at this point in the history
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()`.
  • Loading branch information
milroy committed Jan 8, 2024
1 parent 3d953e3 commit 4392da4
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion resource/policies/dfu_match_multilevel_id_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ int64_t multilevel_id_t<FOLD>::score_factor_t::calc_factor (
return -1;
}
mul = add * m_multiply_by;
tie = break_tie % m_multiply_by - 1;
tie = abs (break_tie % static_cast<int64_t> (m_multiply_by) - 1);

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

0 comments on commit 4392da4

Please sign in to comment.