This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: initstate_r in /lib/libc.so.6 crashing


 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]