Add MEMZERO_ARRAY() macro and use it in coccinelle
A bug was found1 in git-last-modified(1), caused by uninitialized memory. While the bug is fixed, in the discussion after that2 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.
Cc: Jeff King peff@peff.net Signed-off-by: Toon Claes toon@iotcl.com
Changes in v2:
- EDITME: describe what is new in this series revision.
- EDITME: use bulletpoints and terse descriptions.
- Link to v1: https://patch.msgid.link/20251210-toon-cocci-memzero-v1-0-ae916a79065b@iotcl.com
--- b4-submit-tracking ---
This section is used internally by b4 prep for tracking purposes.
{ "series": { "revision": 2, "change-id": "20251210-toon-cocci-memzero-2b6185e08ac4", "prefixes": [], "history": { "v1": [ "20251210-toon-cocci-memzero-v1-0-ae916a79065b@iotcl.com" ] } } }