From: Toon Claes Date: Wed, 10 Dec 2025 13:13:00 GMT Subject: [PATCH 0/2] Add MEMZERO_ARRAY() macro and use it in coccinelle Message-ID: <20251210-toon-cocci-memzero-v1-0-ae916a79065b@iotcl.com> A bug was found[1] in git-last-modified(1), caused by uninitialized memory. While the bug is fixed, in the discussion after that[2] the suggestion was made to introduce a macro that simplifies zeroing a dynamically allocated array. In the first patch I'm addressing the outcome of the discussion on the patch, and in the second patch I'm fixing an edge-case I've encountered while using coccinelle. There's one /oddball/ in add-patch.c that doesn't get caught by the coccinelle rules, around line 960: memset(hunk + 1, 0, (splittable_into - 1) * sizeof(*hunk)); Because there's some quirky pointer math going on, it think it's better to keep it like it is. There were some mixed opinions about naming it either CLEAR_ARRAY() or MEMZERO_ARRAY(). I choose the latter because I wanted to avoid confusion that "clear" would shrink the array to zero elements. [1]: <4dc4c8cd-c0cc-4784-8fcf-defa3a051087@mit.edu> [2]: <20251208201501.GA216526@coredump.intra.peff.net> Signed-off-by: Toon Claes --- Toon Claes (2): git-compat-util: introduce MEMZERO_ARRAY() macro contrib/coccinelle: pass include paths to spatch(1) Makefile | 2 +- builtin/last-modified.c | 2 +- compat/simple-ipc/ipc-win32.c | 2 +- contrib/coccinelle/array.cocci | 20 ++++++++++++++++++++ contrib/coccinelle/meson.build | 6 ++++++ diff-delta.c | 2 +- ewah/bitmap.c | 7 +++---- git-compat-util.h | 1 + hashmap.c | 2 +- pack-revindex.c | 2 +- 10 files changed, 36 insertions(+), 10 deletions(-) --- base-commit: 011ce54c26318d725db1d8971d157656eb965d88 change-id: 20251210-toon-cocci-memzero-2b6185e08ac4