tolerate additional IPv4 address now available for gnunet.org
[oweals/gnunet.git] / src / util / container_multihashmap32.c
index 72940489eb345cde7dcb53874435e21e0b0a2563..a614c04aef5442e3bd534ad68e5d2be124b75d7d 100644 (file)
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+     SPDX-License-Identifier: AGPL3.0-or-later
 */
 /**
  * @file util/container_multihashmap32.c
@@ -144,8 +146,13 @@ GNUNET_CONTAINER_multihashmap32_create (unsigned int len)
 
   GNUNET_assert (len > 0);
   ret = GNUNET_new (struct GNUNET_CONTAINER_MultiHashMap32);
-  ret->map = GNUNET_new_array (len,
-                              struct MapEntry *);
+  ret->map = GNUNET_malloc_large (len *
+                                  sizeof (struct MapEntry *));
+  if (NULL == ret->map)
+  {
+    GNUNET_free (ret);
+    return NULL;
+  }
   ret->map_length = len;
   return ret;
 }
@@ -266,7 +273,7 @@ GNUNET_CONTAINER_multihashmap32_iterate (struct GNUNET_CONTAINER_MultiHashMap32
                             e->key,
                             e->value))
        {
-         GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE);      
+         GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE);
           return GNUNET_SYSERR;
        }
       }
@@ -461,13 +468,18 @@ grow (struct GNUNET_CONTAINER_MultiHashMap32 *map)
   unsigned int new_len;
   unsigned int idx;
 
-  map->modification_counter++;
-
   old_map = map->map;
   old_len = map->map_length;
   new_len = old_len * 2;
-  new_map = GNUNET_new_array (new_len,
-                             struct MapEntry *);
+  if (0 == new_len) /* 2^31 * 2 == 0 */
+    new_len = old_len; /* never use 0 */
+  if (new_len == old_len)
+    return; /* nothing changed */
+  new_map = GNUNET_malloc_large (new_len *
+                                 sizeof (struct MapEntry *));
+  if (NULL == new_map)
+    return; /* grow not possible */
+  map->modification_counter++;
   map->map_length = new_len;
   map->map = new_map;
   for (unsigned int i = 0; i < old_len; i++)