projects
/
oweals
/
minetest.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Code modernization: src/m* (part 2)
[oweals/minetest.git]
/
src
/
noise.cpp
diff --git
a/src/noise.cpp
b/src/noise.cpp
index f67771b8885e3679b90cc7619cccfd1d73bbedb1..e6ca8a4951cf669c8312275f2b859fc34d2f1297 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)");
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;
}
return range(bound) + min;
}