projects
/
oweals
/
minetest.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
070ab66
)
Noise: Prevent unittest crash caused by division by zero
author
SmallJoker
<mk939@ymail.com>
Sat, 29 Jul 2017 17:01:14 +0000
(19:01 +0200)
committer
SmallJoker
<mk939@ymail.com>
Sun, 3 Jun 2018 15:31:59 +0000
(17:31 +0200)
src/noise.cpp
patch
|
blob
|
history
diff --git
a/src/noise.cpp
b/src/noise.cpp
index b918c9936851ccb638dcf617f1cc6c8ef9dc34fd..abd29f3ecdba2d151d334186f1aee45693e5aa4e 100644
(file)
--- 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;
}