* stdlib/random_r.c (__setstate_r): Allow call with same state
	array as currently used (PR libc/774).
This commit is contained in:
Ulrich Drepper 1998-09-10 17:07:03 +00:00
parent 6c79e60c34
commit 26afaa6357
2 changed files with 9 additions and 2 deletions

View File

@ -1,5 +1,8 @@
1998-09-10 Ulrich Drepper <drepper@cygnus.com> 1998-09-10 Ulrich Drepper <drepper@cygnus.com>
* stdlib/random_r.c (__setstate_r): Allow call with same state
array as currently used (PR libc/774).
* include/limits.h: Include gcc's header even if this file is * include/limits.h: Include gcc's header even if this file is
found more than once before it (PR libc/778) found more than once before it (PR libc/778)

View File

@ -268,13 +268,13 @@ __setstate_r (arg_state, buf)
struct random_data *buf; struct random_data *buf;
{ {
int32_t *new_state = (int32_t *) arg_state; int32_t *new_state = (int32_t *) arg_state;
int type = new_state[0] % MAX_TYPES; int type;
int old_type; int old_type;
int32_t *old_state; int32_t *old_state;
int degree; int degree;
int separation; int separation;
if (buf == NULL || type < TYPE_0 || type >= TYPE_4) if (buf == NULL)
goto fail; goto fail;
old_type = buf->rand_type; old_type = buf->rand_type;
@ -284,6 +284,10 @@ __setstate_r (arg_state, buf)
else else
old_state[-1] = (MAX_TYPES * (buf->rptr - old_state)) + old_type; old_state[-1] = (MAX_TYPES * (buf->rptr - old_state)) + old_type;
type = new_state[0] % MAX_TYPES;
if (type < TYPE_0 || type >= TYPE_4)
goto fail;
buf->rand_deg = degree = random_poly_info.degrees[type]; buf->rand_deg = degree = random_poly_info.degrees[type];
buf->rand_sep = separation = random_poly_info.seps[type]; buf->rand_sep = separation = random_poly_info.seps[type];
buf->rand_type = type; buf->rand_type = type;