initstate_r in /lib/libc.so.6 crashing
Ángel González
keisial@gmail.com
Mon Jun 27 22:20:00 GMT 2011
El 27/06/11 00:26, Zeno escribió:
> 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.
>
Do you have a prototype for all functions?
According to the man page initstate_r needs _SVID_SOURCE
or _BSD_SOURCE to be defined (seems to work without them here, though).
I don't see time.h either.
What's the size of your time_t? If the compiler thought it was 32 bits
(eg. by
an implied function), but initstate_r expects 64 bits, there will be a
disagreement on what the different pieces at the stack are, andtaking
something
different as an address would explain the crash.
More information about the Libc-help
mailing list