OSDN Git Service

QDict: Fix size update
authorLuiz Capitulino <lcapitulino@redhat.com>
Mon, 14 Dec 2009 20:53:20 +0000 (18:53 -0200)
committerAnthony Liguori <aliguori@us.ibm.com>
Fri, 18 Dec 2009 17:26:27 +0000 (11:26 -0600)
Key replacement should not update the dictionary's size.

This commit also adds a test for the bug.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
check-qdict.c
qdict.c

index c37d448..f2b4826 100644 (file)
@@ -205,6 +205,8 @@ START_TEST(qdict_put_exists_test)
 
     value = qdict_get_int(tests_dict, key);
     fail_unless(value == 2);
+
+    fail_unless(qdict_size(tests_dict) == 1);
 }
 END_TEST
 
diff --git a/qdict.c b/qdict.c
index ef73265..ba8eef0 100644 (file)
--- a/qdict.c
+++ b/qdict.c
@@ -122,9 +122,8 @@ void qdict_put_obj(QDict *qdict, const char *key, QObject *value)
         /* allocate a new entry */
         entry = alloc_entry(key, value);
         QLIST_INSERT_HEAD(&qdict->table[hash], entry, next);
+        qdict->size++;
     }
-
-    qdict->size++;
 }
 
 /**