diff options
author | David Herrmann <dh.herrmann@gmail.com> | 2015-06-14 16:51:35 +0200 |
---|---|---|
committer | David Herrmann <dh.herrmann@gmail.com> | 2015-06-14 16:56:02 +0200 |
commit | 8927b1dad2d4a7330174cb924090b4635a2547fb (patch) | |
tree | aa730ee2822e083e988f7621fcafefd65006b844 /src/basic/ordered-set.h | |
parent | aa75494ad5cdf7bede947212ad8c8356d78580fa (diff) |
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.
Diffstat (limited to 'src/basic/ordered-set.h')
-rw-r--r-- | src/basic/ordered-set.h | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/basic/ordered-set.h b/src/basic/ordered-set.h index 766a1f2e83..6c617ab305 100644 --- a/src/basic/ordered-set.h +++ b/src/basic/ordered-set.h @@ -47,12 +47,12 @@ static inline bool ordered_set_isempty(OrderedSet *s) { return ordered_hashmap_isempty((OrderedHashmap*) s); } -static inline void *ordered_set_iterate(OrderedSet *s, Iterator *i) { - return ordered_hashmap_iterate((OrderedHashmap*) s, i, NULL); +static inline bool ordered_set_iterate(OrderedSet *s, Iterator *i, void **value) { + return ordered_hashmap_iterate((OrderedHashmap*) s, i, value, NULL); } #define ORDERED_SET_FOREACH(e, s, i) \ - for ((i) = ITERATOR_FIRST, (e) = ordered_set_iterate((s), &(i)); (e); (e) = ordered_set_iterate((s), &(i))) + for ((i) = ITERATOR_FIRST; ordered_set_iterate((s), &(i), (void**)&(e)); ) DEFINE_TRIVIAL_CLEANUP_FUNC(OrderedSet*, ordered_set_free); |