diff options
| author | Toon Claes <toon@iotcl.com> | 2025-12-10 14:13:01 +0100 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2025-12-11 14:44:43 +0900 |
| commit | a67b902c94a2f33275a3947a8bcdab03f64ae75e (patch) | |
| tree | c5e00364a71a55934e1d2c13abf31a7474e5478d /contrib | |
| parent | af0ed97e1031f2709dbd4fc4f40c4ded711acd49 (diff) | |
git-compat-util: introduce MEMZERO_ARRAY() macro
Introduce a new macro MEMZERO_ARRAY() that zeroes the memory allocated
by ALLOC_ARRAY() and friends. And add coccinelle rule to enforce the use
of this macro.
Signed-off-by: Toon Claes <toon@iotcl.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'contrib')
| -rw-r--r-- | contrib/coccinelle/array.cocci | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/contrib/coccinelle/array.cocci b/contrib/coccinelle/array.cocci index 27a3b479c9..d306f6a21e 100644 --- a/contrib/coccinelle/array.cocci +++ b/contrib/coccinelle/array.cocci @@ -101,3 +101,23 @@ expression dst, src, n; -ALLOC_ARRAY(dst, n); -COPY_ARRAY(dst, src, n); +DUP_ARRAY(dst, src, n); + +@@ +type T; +T *ptr; +expression n; +@@ +- memset(ptr, \( 0x0 \| 0 \), n * \( sizeof(T) +- \| sizeof(*ptr) +- \) ) ++ MEMZERO_ARRAY(ptr, n) + +@@ +type T; +T[] ptr; +expression n; +@@ +- memset(ptr, \( 0x0 \| 0 \), n * \( sizeof(T) +- \| sizeof(*ptr) +- \) ) ++ MEMZERO_ARRAY(ptr, n) |
