mirror of
https://github.com/Cubitect/cubiomes.git
synced 2025-09-20 09:58:29 -04:00
Fix undefined overflow behavior
This commit is contained in:
parent
0af31b4e7e
commit
681906b983
4
rng.h
4
rng.h
@ -108,7 +108,7 @@ static inline int nextInt(uint64_t *seed, const int n)
|
||||
bits = next(seed, 31);
|
||||
val = bits % n;
|
||||
}
|
||||
while (bits - val + m < 0);
|
||||
while (((int32_t)((uint32_t)bits - val + m) < 0));
|
||||
return val;
|
||||
}
|
||||
|
||||
@ -261,7 +261,7 @@ static inline int xNextIntJ(Xoroshiro *xr, uint32_t n)
|
||||
bits = (xNextLong(xr) >> 33);
|
||||
val = bits % n;
|
||||
}
|
||||
while (bits - val + m < 0);
|
||||
while (((int32_t)((uint32_t)bits - val + m) < 0));
|
||||
return val;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user