From 9c3b0ac5c30b749e4158014648d85f6b4b3dd23a Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Mon, 12 Nov 2012 16:07:12 +0000 Subject: [PATCH] edbus: fix checking if root objects are our son strncmp'ing is not sufficient because it whould fail in case an object like "/org/bla" is registered (and in conn->root_objs) and we were registering "/org/blatest/". We would incorrectly put "/org/bla" as son of "/org/blatest". Fix this by looking up the next char, checking if it's a slash. Also re-format the code a little bit. SVN revision: 79179 --- src/lib/edbus_service.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/lib/edbus_service.c b/src/lib/edbus_service.c index 2697a76..6b12472 100644 --- a/src/lib/edbus_service.c +++ b/src/lib/edbus_service.c @@ -514,8 +514,9 @@ _edbus_service_object_parent_find(EDBus_Service_Object *obj) static EDBus_Service_Object * _edbus_service_object_add(EDBus_Connection *conn, const char *path) { - EDBus_Service_Object *obj, *aux; + EDBus_Service_Object *obj, *rootobj; Eina_Inlist *safe; + size_t pathlen; obj = calloc(1, sizeof(EDBus_Service_Object)); EINA_SAFETY_ON_NULL_RETURN_VAL(obj, NULL); @@ -543,16 +544,24 @@ _edbus_service_object_add(EDBus_Connection *conn, const char *path) return obj; } - EINA_INLIST_FOREACH_SAFE(conn->root_objs, safe, aux) + /* + * If there wasn't any object above us, check if anyone in conn->root_obj + * should become our child and append ourselves there. + */ + pathlen = strlen(obj->path); + EINA_INLIST_FOREACH_SAFE(conn->root_objs, safe, rootobj) { - if (!strncmp(obj->path, aux->path, strlen(obj->path))) - { - conn->root_objs = eina_inlist_remove(conn->root_objs, - EINA_INLIST_GET(aux)); - obj->children = eina_inlist_append(obj->children, - EINA_INLIST_GET(aux)); - aux->parent = obj; - } + if (strncmp(obj->path, rootobj->path, pathlen) != 0) + continue; + + if (rootobj->path[pathlen] != '/') + continue; + + conn->root_objs = eina_inlist_remove(conn->root_objs, + EINA_INLIST_GET(rootobj)); + obj->children = eina_inlist_append(obj->children, + EINA_INLIST_GET(rootobj)); + rootobj->parent = obj; } conn->root_objs = eina_inlist_append(conn->root_objs, EINA_INLIST_GET(obj)); -- 2.7.4