Re: [gtk-list] Bug in g_list_remove?



On Sun, 13 Sep 1998, Robin Ericsson wrote:

> 
>   I've found some problem with the g_list_remove(). When I call it on the first
> object in the link, the ->next pointers got skrewie, and another call I made to
> the ->data crashed my app. The version of GTK+ and Glib I'm running was
> something I pulled from the CVS tree last week. When I go online to port this
> letter I'll get the latest source to see if it has been fixed.
> 
>   This is the fix I did in my source:
> 
>   WIZARD_DATA *w;
>   GList       *list1; /* this one is global, put it here to show you */
> 
>     if ( w == list1->data )
>     {
>         GList *tmp;
>         
>         tmp = list1->next;
>         tmp->prev = NULL;
>     
>         g_list_free_1 (list1);
>         list1 = tmp;
>     }
>     else
>         g_list_remove (list1, w);

g_list_remove() will delete the item that contains the data in question.
"delete" here means that the node containg `data' will be unlinked from
your list and put into a global free-nodes-list, maintained by glib.
that's why you encounter your ->next pointer to be screwed. if the node
containing `data' is the first node in the list, your head obviously
needs to change, so that your list1 pointer will point to the second
element of your original list that's why g_list_remove() returns a new
GList* pointer, like most of the g_list_* functions do.
so the correct way to delete `w' off of list1 is:

list1 = g_list_remove (list1, w);

>   
>   It was when I called g_list_remove (list1, w); all the time it went screwie.
> 

---
ciaoTJ



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