mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Noise: Prevent unittest crash caused by division by zero
This commit is contained in:
parent
e9d7005799
commit
765fd9a0bc
1 changed files with 3 additions and 1 deletions
|
@ -130,7 +130,9 @@ s32 PcgRandom::range(s32 min, s32 max)
|
||||||
if (max < min)
|
if (max < min)
|
||||||
throw PrngException("Invalid range (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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue