mirror of
git://sourceware.org/git/glibc.git
synced 2025-03-06 20:58:33 +01:00
stdlib: Fix unintended change to the random_r implementation
Commitd5bceac99d
changed the sequence of random numbers. This was completely unintended. The statistical properties of the new sequences are unclear, so restore the old behavior. Fixes commitd5bceac99d
("stdlib: random_r: fix unaligned access in initstate and initstate_r [BZ #30584]"). Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
This commit is contained in:
parent
a3131e71cf
commit
33b684e019
1 changed files with 4 additions and 3 deletions
|
@ -390,9 +390,10 @@ __random_r (struct random_data *buf, int32_t *result)
|
|||
int32_t *end_ptr = buf->end_ptr;
|
||||
uint32_t val;
|
||||
|
||||
val = read_state (rptr, 0);
|
||||
int32_t t = read_state (fptr, 0);
|
||||
write_state (fptr, 0, t + val);
|
||||
/* Avoid integer overflow with uint32_t arihmetic. */
|
||||
val = read_state (fptr, 0);
|
||||
val += read_state (rptr, 0);
|
||||
write_state (fptr, 0, val);
|
||||
/* Chucking least random bit. */
|
||||
*result = val >> 1;
|
||||
++fptr;
|
||||
|
|
Loading…
Add table
Reference in a new issue