diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2023-02-11 22:04:48 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2023-02-11 22:04:48 +0100 |
commit | bc08b48b6af5e49a71a470f445167af35ab58577 (patch) | |
tree | f35c26fda7d349a28a9e4531a6037d6af126062b /core | |
parent | 9f7744ee0e8ac6808bee2f29e44f09a85f6d5766 (diff) | |
parent | f011d8ca9ca25232fb335eead1c8eeaf5c7f2c54 (diff) |
Merge pull request #73119 from akien-mga/math-posmod-no-div0
Math: Prevent division by zero in posmod
Diffstat (limited to 'core')
-rw-r--r-- | core/math/math_funcs.h | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h index 0fa82bb8c1..078320d620 100644 --- a/core/math/math_funcs.h +++ b/core/math/math_funcs.h @@ -31,6 +31,7 @@ #ifndef MATH_FUNCS_H #define MATH_FUNCS_H +#include "core/error/error_macros.h" #include "core/math/math_defs.h" #include "core/math/random_pcg.h" #include "core/typedefs.h" @@ -225,6 +226,7 @@ public: } static _ALWAYS_INLINE_ int64_t posmod(int64_t p_x, int64_t p_y) { + ERR_FAIL_COND_V_MSG(p_y == 0, 0, "Division by zero in posmod is undefined. Returning 0 as fallback."); int64_t value = p_x % p_y; if (((value < 0) && (p_y > 0)) || ((value > 0) && (p_y < 0))) { value += p_y; |