This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: initstate_r in /lib/libc.so.6 crashing
- From: Zeno <zenomcdohl at gmail dot com>
- To: libc-help at sourceware dot org
- Date: Sun, 26 Jun 2011 18:26:42 -0400
- Subject: Re: initstate_r in /lib/libc.so.6 crashing
- References: <BANLkTimcbi4MV182oU6umG8F01M0ynjxBA@mail.gmail.com>
I am getting a crash when trying to use initstate_r:
(gdb) run
Starting program: /home/user/test.out
Program received signal SIGSEGV, Segmentation fault.
0x40052d00 in initstate_r () from /lib/libc.so.6
The code:
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define STATELEN ? ?256 ? ? ? ? ? ? /* random number state buffer */
main()
{
?char randomStateBuffer[STATELEN];
?struct random_data randData;
?printf("Before initstate");
? /* seed the random number generator */
? ?initstate_r (time(NULL), (char *)&randomStateBuffer, STATELEN,
? (struct random_data *)&randData);
?printf("initstate done");
}
This code also crashes:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
typedef struct random_data random_data;
int main() {
?char statebuf[256];
?random_data randomData;
?memset(&randomData, 0, sizeof(randomData));
?initstate_r(0, statebuf, 256, &randomData);
?return 0;
}
Any ideas? Thanks.
Here's a valgrind of what happens: http://pastebin.com/w7qcRgnr