summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSmallJoker <mk939@ymail.com>2017-07-29 19:01:14 +0200
committerSmallJoker <mk939@ymail.com>2018-06-03 17:31:59 +0200
commit4be7d8b43a68664b6c349918ab79174ec6a3a24c (patch)
tree83a9a9ca1d9cc4843a5743e8d68dc21bb6490ed1
parent070ab6654ab4d8ab4a15a99698666f27552d6937 (diff)
downloadminetest-4be7d8b43a68664b6c349918ab79174ec6a3a24c.tar.gz
minetest-4be7d8b43a68664b6c349918ab79174ec6a3a24c.tar.bz2
minetest-4be7d8b43a68664b6c349918ab79174ec6a3a24c.zip
Noise: Prevent unittest crash caused by division by zero
-rw-r--r--src/noise.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/noise.cpp b/src/noise.cpp
index b918c9936..abd29f3ec 100644
--- a/src/noise.cpp
+++ b/src/noise.cpp
@@ -130,7 +130,9 @@ s32 PcgRandom::range(s32 min, s32 max)
if (max < min)
throw PrngException("Invalid range (max < min)");
- u32 bound = max - min + 1;
+ // We have to cast to s64 because otherwise this could overflow,
+ // and signed overflow is undefined behavior.
+ u32 bound = (s64)max - (s64)min + 1;
return range(bound) + min;
}