aboutsummaryrefslogtreecommitdiff
path: root/stdlib/random_r.c
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/random_r.c')
-rw-r--r--stdlib/random_r.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/stdlib/random_r.c b/stdlib/random_r.c
index 605e96983c..b49f03f5be 100644
--- a/stdlib/random_r.c
+++ b/stdlib/random_r.c
@@ -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;