fix hashmap iterator skipping the second element in some cases

Mon, 20 Mar 2023 18:05:12 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 20 Mar 2023 18:05:12 +0100
changeset 665
c4041b07165e
parent 664
af5bf4603a5d
child 666
b5dd654deb3b

fix hashmap iterator skipping the second element in some cases

src/hash_map.c file | annotate | diff | comparison | revisions
--- a/src/hash_map.c	Tue Mar 14 20:25:24 2023 +0100
+++ b/src/hash_map.c	Mon Mar 20 18:05:12 2023 +0100
@@ -339,8 +339,8 @@
     if (map->size > 0) {
         struct cx_hash_map_s *hash_map = (struct cx_hash_map_s *) map;
         struct cx_hash_map_element_s *elm = hash_map->buckets[0];
-        for (; elm == NULL; iter.slot++) {
-            elm = hash_map->buckets[iter.slot];
+        while (elm == NULL) {
+            elm = hash_map->buckets[++iter.slot];
         }
         iter.elem_handle = elm;
         iter.kv_data.key = &elm->key;

mercurial