Subject: Re: [PATCH v2] last-modified: fix use of uninitialized memory

From: Junio C Hamano <[email-masked]>
Date: Mon, 08 Dec 2025 22:26:38 +0900

Toon Claes <[email-masked]> writes:

> Changes in v2:
> - Defined and used MEMZERO_ARRAY() macro.
> - Fixed up title which used unexisting word
> - Link to v1: https://lore.kernel.org/r/[email-masked]

Sorry, but hasn't the old one already been cooking in 'next'?

> ---
>  builtin/last-modified.c | 2 +-
>  git-compat-util.h       | 1 +
>  2 files changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/builtin/last-modified.c b/builtin/last-modified.c
> index b0ecbdc540..ac5387e861 100644
> --- a/builtin/last-modified.c
> +++ b/builtin/last-modified.c
> @@ -327,7 +327,7 @@ static void process_parent(struct last_modified *lm,
>  	if (!(parent->object.flags & PARENT1))
>  		active_paths_free(lm, parent);
>  
> -	memset(lm->scratch->words, 0x0, lm->scratch->word_alloc);
> +	MEMZERO_ARRAY(lm->scratch->words, lm->scratch->word_alloc);
>  	diff_queue_clear(&diff_queued_diff);
>  }
>  
> diff --git a/git-compat-util.h b/git-compat-util.h
> index 398e0fac4f..2b8192fd2e 100644
> --- a/git-compat-util.h
> +++ b/git-compat-util.h
> @@ -726,6 +726,7 @@ static inline uint64_t u64_add(uint64_t a, uint64_t b)
>  #define ALLOC_ARRAY(x, alloc) (x) = xmalloc(st_mult(sizeof(*(x)), (alloc)))
>  #define CALLOC_ARRAY(x, alloc) (x) = xcalloc((alloc), sizeof(*(x)))
>  #define REALLOC_ARRAY(x, alloc) (x) = xrealloc((x), st_mult(sizeof(*(x)), (alloc)))
> +#define MEMZERO_ARRAY(x, alloc) memset((x), 0x0, st_mult(sizeof(*(x)), (alloc)))
>  
>  #define COPY_ARRAY(dst, src, n) copy_array((dst), (src), (n), sizeof(*(dst)) + \
>  	BARF_UNLESS_COPYABLE((dst), (src)))
>
> ---
> base-commit: bdc5341ff65278a3cc80b2e8a02a2f02aa1fac06
> change-id: 20251126-toon-big-endian-ci-fe62bb361974