From: Nathan I. <nin...@gm...> - 2005-07-21 18:50:04
|
Thanks, patch applied to CVS. On 7/21/05, Dylan Shell <ds...@ro...> wrote: > Currently ecore_dlist_append has a bug in that it increments the > list->nodes without considering whether it makes a previously invalid > list->index valid. If this happens, the list has a valid index, and thus > interprets the list->current member as pointing to node data. >=20 > Here is code that shows the invalid behavior in the current implementatio= n: >=20 > =3D=3D=3D=3D=3D BEGIN CODE SNIPPET =3D=3D=3D=3D=3D >=20 > #include <Ecore.h> > #include <Ecore_Data.h> > #include <string.h> > #include <stdlib.h> >=20 > void print_list(Ecore_DList *list) > { > char *item; >=20 > /* Seek to end by looking for NULL */ > ecore_dlist_goto_first(list); > while ((item =3D (char *)ecore_dlist_next(list)) !=3D NULL) > { > printf("%p %s\n", item, item); > } >=20 > printf("\n"); > } >=20 > int main(int argc, const char **argv) > { > char *first =3D "first"; > char *second =3D "second"; > char *p; > int i, nn; >=20 > Ecore_DList *list; >=20 > list =3D ecore_dlist_new(); > ecore_dlist_append(list, first); >=20 > print_list(list); >=20 > ecore_dlist_append(list, second); >=20 > /* Now try another way: */ >=20 > nn =3D ecore_dlist_nodes(list); > for (i =3D 0;i < nn;i++) > { > p =3D ecore_dlist_goto_index(list, i); > printf("%d %p %s\n",i, p, p); >=20 > } >=20 >=20 >=20 > return EXIT_SUCCESS; > } >=20 > =3D=3D=3D=3D=3D END CODE SNIPPET =3D=3D=3D=3D=3D >=20 >=20 > One would expect the "goto_index" print list to print the list, instead > it prints the first element twice. > Below is the patch to CVS head that fixes this. >=20 > =3D=3D=3D=3D=3D BEGIN PATCH =3D=3D=3D=3D=3D >=20 > RCS file: /cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore/ecore_list.= c,v > retrieving revision 1.15 > diff -p -u -r1.15 ecore_list.c > --- ecore_list.c 30 Jun 2005 16:47:29 -0000 1.15 > +++ ecore_list.c 21 Jul 2005 18:22:30 -0000 > @@ -372,6 +372,12 @@ static int _ecore_list_append_0(Ecore_Li > list->current =3D NULL; > } >=20 > + if (list->index >=3D list->nodes) /* Index was out of bounds, ensure > that we don't make it "in bounds" > + but with an invalid current > pointer by incrementing the nodes */ > + list->index++; > + > + > + > list->nodes++; >=20 > return TRUE; >=20 > =3D=3D=3D=3D=3D END PATCH =3D=3D=3D=3D=3D >=20 > Dylan. >=20 >=20 > |