From e9abf8a370b0256f96108048eec95b68ef92effc Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Thu, 6 Jun 2024 15:05:35 -0400 Subject: Prefer 'sizeof(t[n])' over 'sizeof(t)*n' --- builtins/table.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'builtins/table.c') diff --git a/builtins/table.c b/builtins/table.c index 591acc96..6b63be8d 100644 --- a/builtins/table.c +++ b/builtins/table.c @@ -102,7 +102,7 @@ static void maybe_copy_on_write(table_t *t, const TypeInfo *type) } if (t->bucket_info && t->bucket_info->data_refcount) { - int64_t size = sizeof(bucket_info_t) + t->bucket_info->count*sizeof(bucket_t); + int64_t size = sizeof(bucket_info_t) + sizeof(bucket_t[t->bucket_info->count]); t->bucket_info = memcpy(GC_MALLOC(size), t->bucket_info, size); t->bucket_info->data_refcount = 0; } @@ -208,9 +208,9 @@ static void hashmap_resize_buckets(table_t *t, uint32_t new_capacity, const Type { hdebug("About to resize from %u to %u\n", t->bucket_info ? t->bucket_info->count : 0, new_capacity); hshow(t); - int64_t alloc_size = sizeof(bucket_info_t) + (int64_t)(new_capacity)*sizeof(bucket_t); + int64_t alloc_size = sizeof(bucket_info_t) + sizeof(bucket_t[new_capacity]); t->bucket_info = GC_MALLOC_ATOMIC(alloc_size); - memset(t->bucket_info->buckets, 0, (int64_t)new_capacity * sizeof(bucket_t)); + memset(t->bucket_info->buckets, 0, sizeof(bucket_t[new_capacity])); t->bucket_info->count = new_capacity; t->bucket_info->last_free = new_capacity-1; // Rehash: -- cgit v1.2.3