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.

Here is code that shows the invalid behavior in the current implementation:

===== BEGIN CODE SNIPPET =====

#include <Ecore.h>
#include <Ecore_Data.h>
#include <string.h>
#include <stdlib.h>

void print_list(Ecore_DList *list)
{
   char *item;

   /* Seek to end by looking for NULL */
   ecore_dlist_goto_first(list);
   while ((item = (char *)ecore_dlist_next(list)) != NULL)
   {
       printf("%p %s\n", item, item);
   }

   printf("\n");
}

int main(int argc, const char **argv)
{
   char *first = "first";
   char *second = "second";
   char *p;
   int i, nn;

   Ecore_DList *list;

   list = ecore_dlist_new();
   ecore_dlist_append(list, first);

   print_list(list);

   ecore_dlist_append(list, second);

   /* Now try another way: */

   nn = ecore_dlist_nodes(list);
   for (i = 0;i < nn;i++)
   {
       p = ecore_dlist_goto_index(list, i);
       printf("%d %p %s\n",i, p, p);

   }

   return EXIT_SUCCESS;
}

===== END CODE SNIPPET =====


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.

===== BEGIN PATCH =====

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 = NULL;
    }

+ if (list->index >= 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++;

    return TRUE;

===== END PATCH =====

Dylan.




-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September
19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to