Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/dict.c14
-rw-r--r--tests/dict/test_dict.c9
2 files changed, 19 insertions, 4 deletions
diff --git a/common/dict.c b/common/dict.c
index 1b7e787..3aebde7 100644
--- a/common/dict.c
+++ b/common/dict.c
@@ -148,7 +148,15 @@ void *dict_values_next(DICT *dict)
{
struct dict_entry *ptr;
ptr=dict->ptr;
- if (dict->ptr!=NULL)
- dict->ptr=dict->ptr->next;
- return ptr;
+ /* search until we get a non-NULL value */
+ while ((ptr!=NULL)&&(ptr->value==NULL))
+ ptr=ptr->next;
+ /* we went through the whole list */
+ if (ptr==NULL)
+ {
+ dict->ptr=NULL;
+ return NULL;
+ }
+ dict->ptr=ptr->next;
+ return ptr->value;
}
diff --git a/tests/dict/test_dict.c b/tests/dict/test_dict.c
index df1aeff..7cfc169 100644
--- a/tests/dict/test_dict.c
+++ b/tests/dict/test_dict.c
@@ -56,12 +56,19 @@ int main(int UNUSED(argc),char UNUSED(*argv[]))
assert(ret==dict);
ret=dict_get(dict,"key4");
assert(ret==NULL);
-
+
/* remove a key */
dict_put(dict,"kEy3",NULL);
ret=dict_get(dict,"keY3");
assert(ret==NULL);
+ /* loop over dictionary contents */
+ dict_values_first(dict);
+ while ((ret=dict_values_next(dict))!=NULL)
+ {
+ assert(((ret==value1)||(ret==replace2)));
+ }
+
/* free dictionary */
dict_free(dict);