Fix a bug in search of keys 94/15394/1
authorJosé Bollo <jose.bollo@open.eurogiciel.org>
Mon, 20 Jan 2014 14:58:20 +0000 (15:58 +0100)
committerJosé Bollo <jose.bollo@open.eurogiciel.org>
Mon, 20 Jan 2014 14:58:20 +0000 (15:58 +0100)
The function '_vconf_keylist_lookup' coulded return a node
that was not matching the requested 'keyname'. For example,
searching the key "acl" in a list containing "aclxxxx", "acl"
would return the node "aclxxx" instead of "acl".

Also compute the length to be compared only one time, not
at each turn of the loop.

Change-Id: Id26e9d0eace311e5537fbce075f912d0a263f31d
Signed-off-by: José Bollo <jose.bollo@open.eurogiciel.org>
vconf.c

diff --git a/vconf.c b/vconf.c
index a6af153..d1474b1 100755 (executable)
--- a/vconf.c
+++ b/vconf.c
@@ -156,6 +156,7 @@ static keynode_t *_vconf_keylist_lookup(keylist_t *keylist, const char *keyname,
                                 keynode_t **before_keynode)
 {
        keynode_t *found_node, *temp_node = NULL;
+       size_t length = 1 + strlen(keyname);
 
        found_node = _vconf_keylist_headnode(keylist);
 
@@ -165,7 +166,7 @@ static keynode_t *_vconf_keylist_lookup(keylist_t *keylist, const char *keyname,
                        return NULL;
                }
 
-               if (!strncmp(keyname, found_node->keyname, strlen(keyname))) {
+               if (!memcmp(keyname, found_node->keyname, length)) {
                        if (before_keynode) {
                                        *before_keynode = temp_node;
                        }