From 8927b1dad2d4a7330174cb924090b4635a2547fb Mon Sep 17 00:00:00 2001 From: David Herrmann Date: Sun, 14 Jun 2015 16:51:35 +0200 Subject: hashmap: fix iterators to not skip entries Currently, the HASHMAP iterators stop at the first NULL entry in a hashmap. This is non-obvious and breaks users like sd-device, which legitimately store NULL values in a hashmap. Fix all the iterators by taking a pointer to the value storage, instead of returning it. The iterators now return a boolean that tells whether the end of the list was reached. Current users of HASHMAP_FOREACH() are *NOT* changed to explicitly check for NULL. If it turns out, there were users that inserted NULL into hashmaps, but didn't properly check for it during iteration, then we really want to find those and fix them. --- src/test/test-hashmap-plain.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/test') diff --git a/src/test/test-hashmap-plain.c b/src/test/test-hashmap-plain.c index c1a5ccf1f5..057b6c1dc1 100644 --- a/src/test/test-hashmap-plain.c +++ b/src/test/test-hashmap-plain.c @@ -465,6 +465,7 @@ static void test_hashmap_foreach_key(void) { hashmap_put(m, key, (void*) (const char*) "my dummy val"); HASHMAP_FOREACH_KEY(s, key, m, i) { + assert(s); if (!key_found[0] && streq(key, "key 1")) key_found[0] = true; else if (!key_found[1] && streq(key, "key 2")) -- cgit v1.2.3-54-g00ecf