Commit 8af2ff25 authored by A. Wilcox's avatar A. Wilcox 🦊
Browse files

random_r: set `x` before calling savestate_r

Prevents segfault when calling initstate_r.
parent 2b502554
......@@ -103,6 +103,7 @@ int initstate_r(unsigned seed, char *restrict state, size_t size,
return -1;
}
buf->x = (int32_t*)state + 1;
savestate_r(buf);
if (size < 32) {
buf->n = 0;
......@@ -115,7 +116,6 @@ int initstate_r(unsigned seed, char *restrict state, size_t size,
} else {
buf->n = 63;
}
buf->x = (int32_t*)state + 1;
srandom_r(seed, buf);
savestate_r(buf);
return 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment