diff options
Diffstat (limited to 'src/util/container_multihashmap32.c')
-rw-r--r-- | src/util/container_multihashmap32.c | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/src/util/container_multihashmap32.c b/src/util/container_multihashmap32.c index 4b19c7c10..a614c04ae 100644 --- a/src/util/container_multihashmap32.c +++ b/src/util/container_multihashmap32.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -146,8 +146,13 @@ GNUNET_CONTAINER_multihashmap32_create (unsigned int len) | |||
146 | 146 | ||
147 | GNUNET_assert (len > 0); | 147 | GNUNET_assert (len > 0); |
148 | ret = GNUNET_new (struct GNUNET_CONTAINER_MultiHashMap32); | 148 | ret = GNUNET_new (struct GNUNET_CONTAINER_MultiHashMap32); |
149 | ret->map = GNUNET_new_array (len, | 149 | ret->map = GNUNET_malloc_large (len * |
150 | struct MapEntry *); | 150 | sizeof (struct MapEntry *)); |
151 | if (NULL == ret->map) | ||
152 | { | ||
153 | GNUNET_free (ret); | ||
154 | return NULL; | ||
155 | } | ||
151 | ret->map_length = len; | 156 | ret->map_length = len; |
152 | return ret; | 157 | return ret; |
153 | } | 158 | } |
@@ -268,7 +273,7 @@ GNUNET_CONTAINER_multihashmap32_iterate (struct GNUNET_CONTAINER_MultiHashMap32 | |||
268 | e->key, | 273 | e->key, |
269 | e->value)) | 274 | e->value)) |
270 | { | 275 | { |
271 | GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE); | 276 | GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE); |
272 | return GNUNET_SYSERR; | 277 | return GNUNET_SYSERR; |
273 | } | 278 | } |
274 | } | 279 | } |
@@ -463,13 +468,18 @@ grow (struct GNUNET_CONTAINER_MultiHashMap32 *map) | |||
463 | unsigned int new_len; | 468 | unsigned int new_len; |
464 | unsigned int idx; | 469 | unsigned int idx; |
465 | 470 | ||
466 | map->modification_counter++; | ||
467 | |||
468 | old_map = map->map; | 471 | old_map = map->map; |
469 | old_len = map->map_length; | 472 | old_len = map->map_length; |
470 | new_len = old_len * 2; | 473 | new_len = old_len * 2; |
471 | new_map = GNUNET_new_array (new_len, | 474 | if (0 == new_len) /* 2^31 * 2 == 0 */ |
472 | struct MapEntry *); | 475 | new_len = old_len; /* never use 0 */ |
476 | if (new_len == old_len) | ||
477 | return; /* nothing changed */ | ||
478 | new_map = GNUNET_malloc_large (new_len * | ||
479 | sizeof (struct MapEntry *)); | ||
480 | if (NULL == new_map) | ||
481 | return; /* grow not possible */ | ||
482 | map->modification_counter++; | ||
473 | map->map_length = new_len; | 483 | map->map_length = new_len; |
474 | map->map = new_map; | 484 | map->map = new_map; |
475 | for (unsigned int i = 0; i < old_len; i++) | 485 | for (unsigned int i = 0; i < old_len; i++) |