Hi, I keep getting this error message for my code even though I initialized it already.
Code:
= Use of uninitialised value of size 4
= at 0x80484D9: irest_destroy (ilist_destructive.c:55)
= by 0x804865B: iprint (ilist_destructive.c:115)
= by 0x80486F7: main (ilist_destructive.c:128)
= Uninitialised value was created by a stack allocation
= at 0x8048679: main (ilist_destructive.c:122)
= Use of uninitialised value of size 4
= at 0x80484F4: irest_destroy (ilist_destructive.c:58)
= by 0x804865B: iprint (ilist_destructive.c:115)
= by 0x80486F7: main (ilist_destructive.c:128)
= Uninitialised value was created by a stack allocation
= at 0x8048679: main (ilist_destructive.c:122)
= Invalid read of size 4
= at 0x80484D9: irest_destroy (ilist_destructive.c:55)
= by 0x804865B: iprint (ilist_destructive.c:115)
= by 0x80486F7: main (ilist_destructive.c:128)
= Address 0x4 is not stack'd, malloc'd or (recently) free'd
= Process terminating with default action of signal 11 (SIGSEGV)
= Access not within mapped region at address 0x4
= at 0x80484D9: irest_destroy (ilist_destructive.c:55)
= by 0x804865B: iprint (ilist_destructive.c:115)
= by 0x80486F7: main (ilist_destructive.c:128)
= If you believe this happened as a result of a stack
= overflow in your program's main thread (unlikely but
= possible), you can try to increase the size of the
= main thread stack using the --main-stacksize= flag.
= The main thread stack size used in this run was 16777216.
why is it doing that???!?
following is my code. this code should start at line 46.
Code:
ilist irest_destroy(ilist il){
// modifies il to remove the first element, and returns the modified ilist
// frees the memory associated with the first element
// references to il cease to be valid ilists
// the result (if non-empty) must eventually be consumed by one of:
// icons_destroy, irest_destroy, idelete
if (il == NULL) return NULL;
ilist r = il->rest;
ilist head = malloc(sizeof(struct ilist_ADT));
head->first = r->first;
head->rest = NULL;
ilist l_end = head;
for (ilist a = r->rest; a != NULL; a=a->rest){
ilist tmp = malloc(sizeof(struct ilist_ADT));
tmp->first = a->first;
tmp->rest=NULL;
l_end->rest = tmp;
l_end=tmp;
}
free(il);
return head;
}
this is the structure definition used in the above code:
Code:
struct ilist_ADT{
struct ilist_ADT *rest;
int first;
};
typedef ilist_ADT *ilist;