MinGW
[oweals/gnunet.git] / src / util / container_multihashmap.c
index 773b24928b06367f74e5996060cab9c3aa3ff85d..5b66442cb953ff98d911e0bb4c185274f743f79a 100644 (file)
@@ -85,6 +85,7 @@ GNUNET_CONTAINER_multihashmap_create (unsigned int len)
 {
   struct GNUNET_CONTAINER_MultiHashMap *ret;
 
+  GNUNET_assert (len > 0);
   ret = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_MultiHashMap));
   ret->map = GNUNET_malloc (len * sizeof (struct MapEntry *));
   ret->map_length = len;
@@ -192,17 +193,23 @@ GNUNET_CONTAINER_multihashmap_iterate (const struct
   int count;
   unsigned int i;
   struct MapEntry *e;
+  struct MapEntry *n;
+  GNUNET_HashCode kc;
 
   count = 0;
   for (i = 0; i < map->map_length; i++)
     {
-      e = map->map[i];
-      while (e != NULL)
+      n = map->map[i];
+      while (NULL != (e = n))
         {
-          if ((NULL != it) && (GNUNET_OK != it (it_cls, &e->key, e->value)))
-            return GNUNET_SYSERR;
+         n = e->next;
+          if (NULL != it)
+           {
+             kc = e->key;
+             if (GNUNET_OK != it (it_cls, &kc, e->value))
+               return GNUNET_SYSERR;
+           }
           count++;
-          e = e->next;
         }
     }
   return count;
@@ -444,7 +451,7 @@ GNUNET_CONTAINER_multihashmap_get_multiple (const struct
       n = e->next;
       if (0 != memcmp (key, &e->key, sizeof (GNUNET_HashCode)))
        continue;
-      if ((it != NULL) && (GNUNET_OK != it (it_cls, &e->key, e->value)))
+      if ((it != NULL) && (GNUNET_OK != it (it_cls, key, e->value)))
        return GNUNET_SYSERR;
       count++;
     }