Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

stackdump error?!!? 1

Status
Not open for further replies.

NatMinx

Programmer
Jun 24, 2008
10
CA
21 [main] calquery 6044 _cygtls:: handle_exception: Error while dumping state (probably corrupted stack)"
inside that stackdump file, it says "Error:STATUS_ACCESS_VIOLATION"

does anyone know what this means?! :'-(

my code worked like a charm 10 mins ago, I took a break, came back & ran it again (without making any changes) & thats the error I'm getting now!
 
Where did that message come from? From the compiler, from running the program...?
What OS and compiler are you using?
 
typedef struct event_t {
char *event;
char *day;
char *year;
char *location;
} Event;

struct CalendarNode {
Event e;
struct CalendarNode *next;
};

int main (int argc, char **argv) {
.....
struct CalendarNode *list;
Event eee;
.....

add(list, eee);
.....
}

void add(struct CalendarNode *cal, Event someEvent) {
if(cal == NULL) {
cal = (struct CalendarNode *)malloc(sizeof(*cal));
cal->e = someEvent;
cal->next = NULL;

} else {
struct CalendarNode *p = cal;
while(p->next != NULL) {
p = p->next; ----> segfault from here after the last iteration

}
struct CalendarNode *q = (struct CalendarNode *)malloc(sizeof(*cal));
p->next = q;
q->e = someEvent;
q->next = NULL;
}
}

Its coming from cygwin (yes I have windows XP, dont look at me like that! :p)
Now I'm trying it on my skool's linux machine, still getting the segfault...
 
I'm not sure if this is causing your current crash, but it certainly would crash if you pass NULL:
Code:
cal = (struct CalendarNode *)malloc(sizeof([COLOR=red]*cal[/color]));
If cal == NULL, you're de-referencing NULL here and BOOM!

BTW, use [ignore]
Code:
[/ignore] tags around your code... (Click the "Process TGML" link above the Submit Post button to see all the tags you can use)

Also, you shouldn't be casting malloc(). Here's why:
Here are some more useful C/C++ FAQs:
 
but how would i fix the NULL case though?
 
Code:
sizeof( CalendarNode )
instead of
Code:
sizeof( *cal )
 
I'm getting the segfault again :-(

what is wrong with this:::

Code:
typedef struct event_t {
        char *event;
        char *day;
        char *year;
        char *location;
} Event;

struct CalendarNode {
        Event e;
        struct CalendarNode *next;
};

int main (int argc, char **argv) {
    .....
    struct CalendarNode *list;
    Event eee;
    .....

    add(list, eee);
    .....
}

void add(struct CalendarNode *cal, Event someEvent) {
    struct CalendarNode *temp;
    temp = cal;

    if(cal == NULL) {
        cal = malloc(sizeof(*cal));
        cal->e = someEvent;
        cal->next = NULL;

    } else {
        while(temp->next != NULL) {
            temp = temp->next;   ----> segfault from here after the last iteration

        }
        temp->next = malloc(sizeof(*cal));
        temp = temp->next;
        temp->e = someEvent; 
        temp->next = NULL;
    }
}
 
Ahhh ignore the first post... that was the wrong version!

Code:
typedef struct event_t {
        char *event;
        char *day;
        char *year;
        char *location;
} Event;

struct CalendarNode {
        Event e;
        struct CalendarNode *next;
};

int main (int argc, char **argv) {
    .....
    struct CalendarNode **list; --> should this be initialised to null?
    Event eee;
    .....

    add(list, eee);
    .....
}

void add(struct CalendarNode **cal, Event someEvent) {
    !!!!segfault from here!!!!
    struct CalendarNode *temp;
    temp = *cal;

    if(*cal == NULL) {
        cal = malloc(sizeof(struct CalendarNode));
        temp = *cal;

    } else {
        while(temp->next != NULL) {
            temp = temp->next;
        }
        temp->next = malloc(sizeof(struct CalendarNode));
        temp = temp->next;
    }

    temp->e = someEvent; 
    temp->next = NULL;
}
 
Code:
should this be initialised to null?
Yes, all pointers should be initialized to NULL if they aren't initialized to something valid.

I don't think you need to create a CalendarNode **list in main(). A single pointer should suffice: CalendarNode *list
Then when you pass it to add() pass the address of list with the & operator:
Code:
add( &list, eee );

Code:
temp = *cal;
Here you're dereferencing cal before checking if it's NULL, which is probably where it's going BOOM.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top