cocci: use MEMZERO_ARRAY() a bit more

Existing code in files that have been fairly stable trigger the "make coccicheck" suggestions due to the new check. Rewrite them to use MEMZERO_ARRAY() Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Dec 13, 2025 at 10:46 UTC 8ea9492cf3505c379d1c573b02db90e6b480cc75
3 files changed +6 -6
diffcore-delta.c
+2 -2
@@ -56,7 +56,7 @@ static struct spanhash_top *spanhash_rehash(struct spanhash_top *orig)
56 st_mult(sizeof(struct spanhash), sz)));
57 new_spanhash->alloc_log2 = orig->alloc_log2 + 1;
58 new_spanhash->free = INITIAL_FREE(new_spanhash->alloc_log2);
59 - memset(new_spanhash->data, 0, sizeof(struct spanhash) * sz);
59 + MEMZERO_ARRAY(new_spanhash->data, sz);
60 for (i = 0; i < osz; i++) {
61 struct spanhash *o = &(orig->data[i]);
62 int bucket;
@@ -135,7 +135,7 @@ static struct spanhash_top *hash_chars(struct repository *r,
135 st_mult(sizeof(struct spanhash), (size_t)1 << i)));
136 hash->alloc_log2 = i;
137 hash->free = INITIAL_FREE(i);
138 - memset(hash->data, 0, sizeof(struct spanhash) * ((size_t)1 << i));
138 + MEMZERO_ARRAY(hash->data, ((size_t)1 << i));
139
140 n = 0;
141 accum1 = accum2 = 0;
linear-assignment.c
+2 -2
@@ -20,8 +20,8 @@ void compute_assignment(int column_count, int row_count, int *cost,
20 int i, j, phase;
21
22 if (column_count < 2) {
23 - memset(column2row, 0, sizeof(int) * column_count);
24 - memset(row2column, 0, sizeof(int) * row_count);
23 + MEMZERO_ARRAY(column2row, column_count);
24 + MEMZERO_ARRAY(row2column, row_count);
25 return;
26 }
27
shallow.c
+2 -2
@@ -713,7 +713,7 @@ void assign_shallow_commits_to_refs(struct shallow_info *info,
713
714 if (used) {
715 int bitmap_size = DIV_ROUND_UP(pi.nr_bits, 32) * sizeof(uint32_t);
716 - memset(used, 0, sizeof(*used) * info->shallow->nr);
716 + MEMZERO_ARRAY(used, info->shallow->nr);
717 for (i = 0; i < nr_shallow; i++) {
718 const struct commit *c = lookup_commit(the_repository,
719 &oid[shallow[i]]);
@@ -782,7 +782,7 @@ static void post_assign_shallow(struct shallow_info *info,
782
783 trace_printf_key(&trace_shallow, "shallow: post_assign_shallow\n");
784 if (ref_status)
785 - memset(ref_status, 0, sizeof(*ref_status) * info->ref->nr);
785 + MEMZERO_ARRAY(ref_status, info->ref->nr);
786
787 /* Remove unreachable shallow commits from "theirs" */
788 for (i = dst = 0; i < info->nr_theirs; i++) {