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


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.




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