git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] Add MEMZERO_ARRAY() macro and use it in coccinelle
@ 2025-12-10 13:13 Toon Claes
  2025-12-10 13:13 ` [PATCH 1/2] git-compat-util: introduce MEMZERO_ARRAY() macro Toon Claes
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Toon Claes @ 2025-12-10 13:13 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Toon Claes

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


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2025-12-19  9:17 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-10 13:13 [PATCH 0/2] Add MEMZERO_ARRAY() macro and use it in coccinelle Toon Claes
2025-12-10 13:13 ` [PATCH 1/2] git-compat-util: introduce MEMZERO_ARRAY() macro Toon Claes
2025-12-11  3:18   ` Junio C Hamano
2025-12-12 13:02     ` René Scharfe
2025-12-19  9:17       ` Toon Claes
2025-12-10 13:13 ` [PATCH 2/2] contrib/coccinelle: pass include paths to spatch(1) Toon Claes
2025-12-11  6:19   ` Patrick Steinhardt
2025-12-12  5:04     ` Junio C Hamano
2025-12-13  1:22   ` Junio C Hamano
2025-12-13  0:18 ` [PATCH 0/2] Add MEMZERO_ARRAY() macro and use it in coccinelle Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).