So I have a structure and when I initiate one, I use malloc as so:
typedef struct node{
void *value;
struct node *next;
} node;
typedef struct QueueADT{
int (*cmp)(const void*a, const void*b);
struct node *front;
int len;
struct node *back;
} * QueueADT;
QueueADT que_create( int (*cmp)(const void*a, const void*b) ) {
printf("%lu\n",sizeof(QueueADT));
QueueADT q = (QueueADT)malloc(sizeof(QueueADT));
if (q == NULL) {return NULL;}
q->cmp = cmp;
q->len = 0;
return q;
}
valgrind spits out:
Invalid write of size 4
Address 0x5204490 is 8 bytes after a block of size 8 alloc'd
write error pertains to q->len = 0;
I cannot tell what the problem is, am I allocating an incorrect amount of bytes?