From 05130471701b7f42b545e2103f21fad61b67bfb0 Mon Sep 17 00:00:00 2001 From: David Goldblatt Date: Thu, 13 Aug 2020 18:02:25 -0700 Subject: [PATCH] PRNG: Allow a a range argument of 1. This is convenient when the range argument itself is generated from some computation whose value we don't know in advance. --- include/jemalloc/internal/prng.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/include/jemalloc/internal/prng.h b/include/jemalloc/internal/prng.h index 12380b41..a309e962 100644 --- a/include/jemalloc/internal/prng.h +++ b/include/jemalloc/internal/prng.h @@ -133,7 +133,9 @@ prng_range_u32(atomic_u32_t *state, uint32_t range, bool atomic) { uint32_t ret; unsigned lg_range; - assert(range > 1); + if (range == 1) { + return 0; + } /* Compute the ceiling of lg(range). */ lg_range = ffs_u32(pow2_ceil_u32(range)); @@ -151,7 +153,9 @@ prng_range_u64(uint64_t *state, uint64_t range) { uint64_t ret; unsigned lg_range; - assert(range > 1); + if (range == 1) { + return 0; + } /* Compute the ceiling of lg(range). */ lg_range = ffs_u64(pow2_ceil_u64(range)); @@ -169,7 +173,9 @@ prng_range_zu(atomic_zu_t *state, size_t range, bool atomic) { size_t ret; unsigned lg_range; - assert(range > 1); + if (range == 1) { + return 0; + } /* Compute the ceiling of lg(range). */ lg_range = ffs_u64(pow2_ceil_u64(range));