Fix overflow in prng_range().

Add jemalloc_ffs64() and use it instead of jemalloc_ffsl() in
prng_range(), since long is not guaranteed to be a 64-bit type.
This commit is contained in:
Jason Evans
2016-02-20 23:41:33 -08:00
parent aac93f414e
commit ecae12323d
5 changed files with 40 additions and 6 deletions

View File

@@ -64,7 +64,7 @@ prng_range(uint64_t *state, uint64_t range)
assert(range > 1);
/* Compute the ceiling of lg(range). */
lg_range = jemalloc_ffsl(pow2_ceil_u64(range)) - 1;
lg_range = jemalloc_ffs64(pow2_ceil_u64(range)) - 1;
/* Generate a result in [0..range) via repeated trial. */
do {