From 545407b3b250edd0a05e314a0b5cf73cdb5a74fa 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/libelogind/sd-hwdb/sd-hwdb.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/libelogind/sd-hwdb') diff --git a/src/libelogind/sd-hwdb/sd-hwdb.c b/src/libelogind/sd-hwdb/sd-hwdb.c index 2a0e00f7d..40aa77ee5 100644 --- a/src/libelogind/sd-hwdb/sd-hwdb.c +++ b/src/libelogind/sd-hwdb/sd-hwdb.c @@ -449,7 +449,8 @@ _public_ int sd_hwdb_seek(sd_hwdb *hwdb, const char *modalias) { } _public_ int sd_hwdb_enumerate(sd_hwdb *hwdb, const char **key, const char **value) { - const void *k, *v; + const void *k; + void *v; assert_return(hwdb, -EINVAL); assert_return(key, -EINVAL); @@ -458,7 +459,7 @@ _public_ int sd_hwdb_enumerate(sd_hwdb *hwdb, const char **key, const char **val if (hwdb->properties_modified) return -EAGAIN; - v = ordered_hashmap_iterate(hwdb->properties, &hwdb->properties_iterator, &k); + ordered_hashmap_iterate(hwdb->properties, &hwdb->properties_iterator, &v, &k); if (!k) return 0; -- cgit v1.2.3