git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 0/2] Add MEMZERO_ARRAY() macro and use it in coccinelle

From
Toon Claes <toon@iotcl.com>
Date
Dec 10, 2025, 13:13 UTC
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@iotcl.com>
---
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

Next: Toon Claes
Message 1 of 10 in “Add MEMZERO_ARRAY() macro and use it in coccinelle”
  1. 0/2 Add MEMZERO_ARRAY() macro and use it in coccinelleToon Claes, Dec 10, 2025
  2. 1/2 git-compat-util: introduce MEMZERO_ARRAY() macroToon Claes, Dec 10, 2025
  3. Junio C HamanoDec 11, 2025
  4. René ScharfeDec 12, 2025
  5. Toon ClaesDec 19, 2025
  6. 2/2 contrib/coccinelle: pass include paths to spatch(1)Toon Claes, Dec 10, 2025
  7. Patrick SteinhardtDec 11, 2025
  8. Junio C HamanoDec 12, 2025
  9. Junio C HamanoDec 13, 2025
  10. Junio C HamanoDec 13, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.