mirror of
https://github.com/godotengine/godot.git
synced 2025-10-28 04:04:24 +00:00
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:
parent
13a0d6e9b2
commit
8747c67d9e
14 changed files with 81 additions and 41 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue