diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2019-06-12 23:07:39 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-12 23:07:39 +0200 |
commit | b44488d823d02702b0150ab5cd4f32a647a330dd (patch) | |
tree | f4c9b64f7c9c2faac845a229feaba6c0a6bf8d85 | |
parent | 1a9a2c879adbcad2eb2ebac0e0c6a081bcc6310c (diff) | |
parent | d89478975f7f97727eea5b865a332efdb4ec9c9d (diff) |
Merge pull request #29702 from KoBeWi/fix_random_crash
Validate parameters of randi_range()
-rw-r--r-- | core/math/random_number_generator.h | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/core/math/random_number_generator.h b/core/math/random_number_generator.h index 6b6bcdd2cd..a6182a4b33 100644 --- a/core/math/random_number_generator.h +++ b/core/math/random_number_generator.h @@ -59,7 +59,10 @@ public: _FORCE_INLINE_ int randi_range(int from, int to) { unsigned int ret = randbase.rand(); - return ret % (to - from + 1) + from; + if (to < from) + return ret % (from - to + 1) + to; + else + return ret % (to - from + 1) + from; } RandomNumberGenerator(); |