Fix potential integer underflow in rounded up divisions

A new `Math::division_round_up()` function was added, allowing for easy
and correct computation of integer divisions when the result needs to
be rounded up.

Fixes #80358.

Co-authored-by: Rémi Verschelde <rverschelde@gmail.com>
This commit is contained in:
EddieBreeg 2023-08-07 20:19:20 +02:00 committed by Rémi Verschelde
parent 13a0d6e9b2
commit 8747c67d9e
No known key found for this signature in database
GPG key ID: C3336907360768E1
14 changed files with 81 additions and 41 deletions

View file

@ -194,9 +194,9 @@ struct GDScriptUtilityFunctionsDefinitions {
// Calculate how many.
int count = 0;
if (incr > 0) {
count = ((to - from - 1) / incr) + 1;
count = Math::division_round_up(to - from, incr);
} else {
count = ((from - to - 1) / -incr) + 1;
count = Math::division_round_up(from - to, -incr);
}
Error err = arr.resize(count);