I have a structure allocated like so:
static struct cparray_buffer_t *_cparray;
struct __attribute__ ((__packed__)) cparray_buffer_t
{
u_int64_t buflen;
u_char buf[buffersize];
}
.
.
.
_cparray = (struct cparray_buffer_t *)calloc(1024, sizeof(struct cparray_buffer_t);
and later on in the program I try to do a memcpy like so
memcpy(_cparray[0].buf, test, buffersize);
and I get a sigsegv
Am I making the reference correctly in the memcpy?
edit: in gdb, it seems like the address for _cparray is 0x0 when it comes time to actually use the array. I tried to put a data watchpoint on _cparray and I don't see anything freeing it. Interestingly enough, if I put a watching on &_cparray it still has a valid address, but *&_cparray is 0x0
edit2: Don't know if it makes a difference, but the calloc is in thread1, and the segfault is happening in thread2. I was under the impression global statics are visible to all threads though. is this correct?
Thanks
What is going on?
Here is the output from the watchpoint on _cparray
Old value = (struct cparray_buffer_t *) 0x284ba000
New value = (struct cparray_buffer_t *) 0x0
0x28102c83 in sem_init () from /lib/libc.so.7