aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2026-02-13 13:39:24 -0800
committerJunio C Hamano <gitster@pobox.com>2026-02-13 13:39:24 -0800
commitb8524125239a2dd9bbc2bc87deda475f9cc3580e (patch)
tree4bdd70670cbaf567ae2ab3ef4d749a5b298d897f
parent453e7b744aef0d9dab62dac6ab030bb643a2e117 (diff)
parent60614838a44591c1449f939236f396bb7164b5ef (diff)
downloadgit-b8524125239a2dd9bbc2bc87deda475f9cc3580e.tar.xz
Merge branch 'tc/memzero-array'
Coccinelle rules update. * tc/memzero-array: cocci: extend MEMZERO_ARRAY() rules
-rw-r--r--contrib/coccinelle/array.cocci36
-rw-r--r--diffcore-delta.c2
-rw-r--r--ewah/bitmap.c4
3 files changed, 33 insertions, 9 deletions
diff --git a/contrib/coccinelle/array.cocci b/contrib/coccinelle/array.cocci
index d306f6a21e..e71baea00b 100644
--- a/contrib/coccinelle/array.cocci
+++ b/contrib/coccinelle/array.cocci
@@ -107,9 +107,32 @@ type T;
T *ptr;
expression n;
@@
-- memset(ptr, \( 0x0 \| 0 \), n * \( sizeof(T)
-- \| sizeof(*ptr)
-- \) )
+- memset(ptr, \( 0 \| '\0' \), \( (n) \| n \) * \( sizeof(T)
+- \| sizeof(ptr[...])
+- \| sizeof(*ptr)
+- \) )
++ MEMZERO_ARRAY(ptr, n)
+
+@@
+type T;
+T *ptr;
+expression n;
+@@
+- memset(ptr, \( 0 \| '\0' \), \( sizeof(T)
+- \| sizeof(ptr[...])
+- \| sizeof(*ptr)
+- \) * \( (n) \| n \) )
++ MEMZERO_ARRAY(ptr, n)
+
+@@
+type T;
+T[] ptr;
+expression n;
+@@
+- memset(ptr, \( 0 \| '\0' \), \( (n) \| n \) * \( sizeof(T)
+- \| sizeof(ptr[...])
+- \| sizeof(*ptr)
+- \) )
+ MEMZERO_ARRAY(ptr, n)
@@
@@ -117,7 +140,8 @@ type T;
T[] ptr;
expression n;
@@
-- memset(ptr, \( 0x0 \| 0 \), n * \( sizeof(T)
-- \| sizeof(*ptr)
-- \) )
+- memset(ptr, \( 0 \| '\0' \), \( sizeof(T)
+- \| sizeof(ptr[...])
+- \| sizeof(*ptr)
+- \) * \( (n) \| n \) )
+ MEMZERO_ARRAY(ptr, n)
diff --git a/diffcore-delta.c b/diffcore-delta.c
index 2de9e9ccff..2b7db39983 100644
--- a/diffcore-delta.c
+++ b/diffcore-delta.c
@@ -135,7 +135,7 @@ static struct spanhash_top *hash_chars(struct repository *r,
st_mult(sizeof(struct spanhash), (size_t)1 << i)));
hash->alloc_log2 = i;
hash->free = INITIAL_FREE(i);
- MEMZERO_ARRAY(hash->data, ((size_t)1 << i));
+ MEMZERO_ARRAY(hash->data, (size_t)1 << i);
n = 0;
accum1 = accum2 = 0;
diff --git a/ewah/bitmap.c b/ewah/bitmap.c
index bf878bf876..c378e0ab78 100644
--- a/ewah/bitmap.c
+++ b/ewah/bitmap.c
@@ -46,7 +46,7 @@ static void bitmap_grow(struct bitmap *self, size_t word_alloc)
{
size_t old_size = self->word_alloc;
ALLOC_GROW(self->words, word_alloc, self->word_alloc);
- MEMZERO_ARRAY(self->words + old_size, (self->word_alloc - old_size));
+ MEMZERO_ARRAY(self->words + old_size, self->word_alloc - old_size);
}
void bitmap_set(struct bitmap *self, size_t pos)
@@ -192,7 +192,7 @@ void bitmap_or_ewah(struct bitmap *self, struct ewah_bitmap *other)
self->word_alloc = other_final;
REALLOC_ARRAY(self->words, self->word_alloc);
MEMZERO_ARRAY(self->words + original_size,
- (self->word_alloc - original_size));
+ self->word_alloc - original_size);
}
ewah_iterator_init(&it, other);