summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2007-07-23 20:24:33 +0000
committerArthur de Jong <arthur@arthurdejong.org>2007-07-23 20:24:33 +0000
commitf7987dfc5745fb6255fdbd2f095f3f17d8a676d6 (patch)
treea95c9cab0f5ff68483fd3db4d4a43073462129b1
parente77242bf31acba871ca3fcaab8cfb808d363262c (diff)
fix a serious bug in dict_values_next() that would return map pointers instead of values and write a test for it
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss-ldapd@315 ef36b2f9-881f-0410-afb5-c4e39611909c
-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);