From 681906b983c2cfc77c76873fc2b1db8088104007 Mon Sep 17 00:00:00 2001 From: DuncanRuns <59705125+DuncanRuns@users.noreply.github.com> Date: Thu, 13 Jun 2024 12:21:19 -0300 Subject: [PATCH] Fix undefined overflow behavior --- rng.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rng.h b/rng.h index b32d4bd..f423256 100644 --- a/rng.h +++ b/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; }