×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

stackdump error?!!?

stackdump error?!!?

stackdump error?!!?

(OP)
"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!

RE: stackdump error?!!?

Where did that message come from?  From the compiler, from running the program...?
What OS and compiler are you using?

RE: stackdump error?!!?

(OP)
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...  

RE: stackdump error?!!?

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(*cal));
If cal == NULL, you're de-referencing NULL here and BOOM!

BTW, use [code][/code] 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: http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1047673478&id=1043284351

Here are some more useful C/C++ FAQs:  http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

RE: stackdump error?!!?

(OP)
but how would i fix the NULL case though?

RE: stackdump error?!!?

CODE

sizeof( CalendarNode )
instead of

CODE

sizeof( *cal )

RE: stackdump error?!!?

(OP)
Thanx a bunch smile big life saver!

RE: stackdump error?!!?

(OP)
I'm getting the segfault again sad

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;
    }
}

RE: stackdump error?!!?

(OP)
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;
}
 

RE: stackdump error?!!?

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close