Returns now GNUNET_SYSERR
[oweals/gnunet.git] / src / util / container_multihashmap.c
index e291b8b50dc3235080efd440edc7cf434b9a785e..b5f663e67b18b2e5935651f0307ba1cb114b48bf 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;
@@ -129,6 +130,7 @@ static unsigned int
 idx_of (const struct GNUNET_CONTAINER_MultiHashMap *m,
         const GNUNET_HashCode * key)
 {
+  GNUNET_assert (m!=NULL);
   return (*(unsigned int *) key) % m->map_length;
 }
 
@@ -192,17 +194,24 @@ GNUNET_CONTAINER_multihashmap_iterate (const struct
   int count;
   unsigned int i;
   struct MapEntry *e;
+  struct MapEntry *n;
+  GNUNET_HashCode kc;
 
   count = 0;
+  GNUNET_assert(map != NULL);
   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;
@@ -435,18 +444,18 @@ GNUNET_CONTAINER_multihashmap_get_multiple (const struct
 {
   int count;
   struct MapEntry *e;
+  struct MapEntry *n;
 
   count = 0;
-  e = map->map[idx_of (map, key)];
-  while (e != NULL)
+  n = map->map[idx_of (map, key)];
+  while (NULL != (e = n))
     {
-      if (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode)))
-        {
-          if ((it != NULL) && (GNUNET_OK != it (it_cls, &e->key, e->value)))
-            return GNUNET_SYSERR;
-          count++;
-        }
-      e = e->next;
+      n = e->next;
+      if (0 != memcmp (key, &e->key, sizeof (GNUNET_HashCode)))
+       continue;
+      if ((it != NULL) && (GNUNET_OK != it (it_cls, key, e->value)))
+       return GNUNET_SYSERR;
+      count++;
     }
   return count;
 }