From d89478975f7f97727eea5b865a332efdb4ec9c9d Mon Sep 17 00:00:00 2001 From: Tomasz Chabora Date: Wed, 12 Jun 2019 03:05:07 +0200 Subject: [PATCH] Validate parameters of randi_range() --- core/math/random_number_generator.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/math/random_number_generator.h b/core/math/random_number_generator.h index 6b6bcdd2cdb..a6182a4b332 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();