aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSmallJoker <mk939@ymail.com>2017-07-29 19:01:14 +0200
committerSmallJoker <mk939@ymail.com>2017-07-29 19:01:14 +0200
commit765fd9a0bc0bb9f08d12713dc586e7f4c59c421d (patch)
treef0641d72793fd5ade8c538f754802b90a4c6a2f8
parente9d70057994172d1b1f52c1ae40842de82a55f86 (diff)
downloadminetest-765fd9a0bc0bb9f08d12713dc586e7f4c59c421d.tar.gz
minetest-765fd9a0bc0bb9f08d12713dc586e7f4c59c421d.tar.bz2
minetest-765fd9a0bc0bb9f08d12713dc586e7f4c59c421d.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 f67771b88..e6ca8a495 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;
}