g_slist_foreach and g_list_foreach functions



Hello,

I ran across a situation where the g_*list_foreach() functions quit
processing before finishing through the list.

In the case of a function being called by g_*list_foreach() that removes the
current list element (via g_slist_remove() ), processing stops, due to the
node being freed.  The small fix below seems to fix that problem, with a
minimal of effort.  Sorry it isn't in diff format, but my that machine isn't
networked.

Any reason why this type of fix couldn't be added?


Paul Kuykendall




void
g_slist_foreach (GSList   *list,
                 GFunc     func,
                 gpointer  user_data)
{
  GSList *nextptr = NULL; /* ADD: */

  while (list)
  {
    nextptr = list->next; /* ADD: */

    (*func) (list->data, user_data);

    /* REMOVE: list = list->next; */

    list = nextptr; /* ADD: */
  }
}





-----
Paul Ryan Kuykendall, Software Engineer
kuykendapr gvl esys com        903-457-8807
Raytheon Company -- Aircraft Integration Systems




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