In FeeFrac::Div(__int128 n, int32_t d, bool round_down)
in src/util/feefrac.h, the following line computes the result:
0 return quot + (mod > 0) - (mod && round_down);
The function can only be called under conditions where the result is in range, and thus doesn’t involve any integer overflow. However, the intermediary result computed by just quot + (mod > 0)
may still overflow if it’s going to be corrected by the - (mod && round_down)
that follows.
Fix this by balancing the two correction steps with each other first:
0 return quot + ((mod > 0) - (mod && round_down));
Fixes #32294.