[Glade-users] unexplainable crash
Olexiy Avramchenko
olexiy@irtech.cn.ua
Mon, 29 Dec 2003 15:37:41 +0200
Hi,
Some comments on your code:
Alef T Veld wrote:
>/* 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"))));
>
Here's a *BUG* - you are trying to use *strcat* on non-initialized char*
pointer. Use *g_strdup()* instead of *strcat()* to duplicate the string
from widget.
> /* Setup the date */
> dateedit1=gnome_date_edit_get_time((GnomeDateEdit *)glade_xml_get_widget(xml,"dateedit1"));
>
>
Get a pointer to widget "dateedit1" first, and use *GNOME_DATE_EDIT()*
cast instead of (GnomeDateEdit*) to be sure that the right widget was
loaded.
> tstruct=localtime(&dateedit1);
>
> /* Get a node */
> if(tail==NULL) {
> g_warning("First record in schedule allocated");
> tail=malloc(sizeof(*tail));
>
1. Use *g_malloc()* or even *g_malloc0()* function instead of
*malloc()* - its easier to debug your app if memory allocation fails.
2. Use GList or GSList data type from GLib - these are already
implemented double and single linked lists. Why are you trying to
reimplement the wheel ?
><...>
>
Olexiy