diff options
author | EddieBreeg <eddiebreeg0@protonmail.com> | 2023-08-07 20:19:20 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2024-01-02 14:14:47 +0100 |
commit | 8747c67d9e549e9b2cf5a93201be105b9c8d9291 (patch) | |
tree | 448bf57e5f613c3111c746b4b6bd2dcc35e7c21d /modules/gdscript/gdscript_utility_functions.cpp | |
parent | 13a0d6e9b253654f5cc2a44f3d0b3cae10440443 (diff) | |
download | redot-engine-8747c67d9e549e9b2cf5a93201be105b9c8d9291.tar.gz |
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>
Diffstat (limited to 'modules/gdscript/gdscript_utility_functions.cpp')
-rw-r--r-- | modules/gdscript/gdscript_utility_functions.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/modules/gdscript/gdscript_utility_functions.cpp b/modules/gdscript/gdscript_utility_functions.cpp index 40c564c36b..dc6ed47ff1 100644 --- a/modules/gdscript/gdscript_utility_functions.cpp +++ b/modules/gdscript/gdscript_utility_functions.cpp @@ -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); |