From fb5b2e5e649cf1a05813f44b466a613e697404fc Mon Sep 17 00:00:00 2001 From: NRK Date: Tue, 3 Jan 2023 02:20:21 +0600 Subject: [PATCH] icons-hash: fix bitwise rotation in case the rotation is 0, `v >> (32 - r)` would end up doing a 32 right shift which is equal to the width of `v` and thus undefined behavior. ref: https://blog.regehr.org/archives/1063 --- src/icons-hash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/icons-hash.c b/src/icons-hash.c index 1b10ae47..da640353 100644 --- a/src/icons-hash.c +++ b/src/icons-hash.c @@ -109,7 +109,7 @@ pcg(uint64_t *state) *state *= GOLDEN_RATIO_64; uint32_t r = (oldstate >> 59); uint32_t v = (oldstate ^ (oldstate >> 18)) >> 27; - return (v >> (32 - r)) | (v << r); + return (v >> (-r & 31)) | (v << r); } int