1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-29 11:41:21 +03:00

(__initstate_r): Don't use non-existing state.

This commit is contained in:
Ulrich Drepper
2005-04-12 15:21:29 +00:00
parent e638c1a2b8
commit fcc3501c22

View File

@ -236,23 +236,20 @@ __initstate_r (seed, arg_state, n, buf)
size_t n; size_t n;
struct random_data *buf; struct random_data *buf;
{ {
int type;
int degree;
int separation;
int32_t *state;
int old_type;
int32_t *old_state;
if (buf == NULL) if (buf == NULL)
goto fail; goto fail;
old_type = buf->rand_type; int32_t *old_state = buf->state;
old_state = buf->state; if (old_state != NULL)
if (old_type == TYPE_0) {
old_state[-1] = TYPE_0; int old_type = buf->rand_type;
else if (old_type == TYPE_0)
old_state[-1] = (MAX_TYPES * (buf->rptr - old_state)) + old_type; old_state[-1] = TYPE_0;
else
old_state[-1] = (MAX_TYPES * (buf->rptr - old_state)) + old_type;
}
int type;
if (n >= BREAK_3) if (n >= BREAK_3)
type = n < BREAK_4 ? TYPE_3 : TYPE_4; type = n < BREAK_4 ? TYPE_3 : TYPE_4;
else if (n < BREAK_1) else if (n < BREAK_1)
@ -267,13 +264,13 @@ __initstate_r (seed, arg_state, n, buf)
else else
type = n < BREAK_2 ? TYPE_1 : TYPE_2; type = n < BREAK_2 ? TYPE_1 : TYPE_2;
degree = random_poly_info.degrees[type]; int degree = random_poly_info.degrees[type];
separation = random_poly_info.seps[type]; int separation = random_poly_info.seps[type];
buf->rand_type = type; buf->rand_type = type;
buf->rand_sep = separation; buf->rand_sep = separation;
buf->rand_deg = degree; buf->rand_deg = degree;
state = &((int32_t *) arg_state)[1]; /* First location. */ int32_t *state = &((int32_t *) arg_state)[1]; /* First location. */
/* Must set END_PTR before srandom. */ /* Must set END_PTR before srandom. */
buf->end_ptr = &state[degree]; buf->end_ptr = &state[degree];