[Glade-users] unexplainable crash



Hello all,

I don't know if this is GTK related or not, i always have a lot of GTK errors mostly due to casting i think,
but here is a weird one. I would appreciate it if someone could tell me if it's the linked list code or the
gtk code involved.

I had put multiple g_warning() statements so i could locate the culprit, but the code seems to be memory
related as it crashes on different times, different code spots. So i'm suspecting the linked list code.

The code is basically a calendar widget with a notebook that tries to connect data put in the notebooks tabs
with a certain date on the calendar widget by matching timestamps.

Thanks very much.

/* cut here */
 char *string;
        schedule *tmp=head;
        time_t dateedit1;
        struct tm *tstruct;

        /* Setup the string */
        strcat(string,gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(xml,"entry1"))));

        /* Setup the date */
        dateedit1=gnome_date_edit_get_time((GnomeDateEdit *)glade_xml_get_widget(xml,"dateedit1"));
        tstruct=localtime(&dateedit1);

        /* Get a node */
        if(tail==NULL) {
        g_warning("First record in schedule allocated");
        tail=malloc(sizeof(*tail));
        tail->string=malloc(sizeof(*string));
        tail->timestamp=malloc(sizeof(asctime(tstruct)));
        strcpy(tail->string,string);
        strcpy(tail->timestamp,asctime(tstruct));
        tail->year=tstruct->tm_year;
        tail->month=tstruct->tm_mon;
        tail->day=tstruct->tm_mday;
        tail->next=NULL;
        head=tail;
        } else {
        g_warning("New record in schedule allocated");
        /* First check if a day is already booked */
        while(tmp!=NULL) {
        if(!strcmp(tmp->timestamp,asctime(tstruct))) {
        g_warning("Date already booked in Calendar Widget");
        gtk_widget_hide(window1);
        return -1;}
        tmp=tmp->next;
        }
        tail->next=malloc(sizeof(*tail));
        tail=tail->next;
        tail->string=malloc(sizeof(*string));
        tail->timestamp=malloc(sizeof(asctime(tstruct)));
        strcpy(tail->string,string);
        strcpy(tail->timestamp,asctime(tstruct));
        tail->year=tstruct->tm_year;
        tail->month=tstruct->tm_mon;
        tail->day=tstruct->tm_mday;
        tail->next=NULL;
        }

        /* And mark the Calendar day so the user will know there's something scheduled */
        gtk_calendar_select_month((GtkCalendar *)glade_xml_get_widget(xml,"calendar1"),
                                                        (guint)tstruct->tm_mon,
                                                        (guint)tstruct->tm_year);

        gtk_calendar_mark_day((GtkCalendar *)glade_xml_get_widget(xml,"calendar1"),(guint)tstruct->tm_mday);

        /* And hide again cause on startup window1 visible=FALSE, we only do gtk_widget_show when user
        presses a button in the app1 window (main app window) */
        gtk_widget_hide(window1);
        }





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]