Re: [PATCH] last-modified: fix bug caused by inproper initialized memory
- From
Toon Claes <toon@iotcl.com>
- Date
- Dec 8, 2025, 11:47 UTC
- Message-ID
- <87bjk9w5yv.fsf@iotcl.com>
- In-Reply-To
- <20251128205514.GA605489@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 23 quoted lines
> I think this patch makes sense as the most obvious and immediate fix. > But thinking on how we might have avoided this bug: > > - We have macros like ALLOC_ARRAY() and COPY_ARRAY() that > automatically multiply the array length by the size of each element > (by looking at the type of the array). We could in theory have a > helper like: > > MEMSET_ARRAY(lm->scratch->words, 0x0, lm->scratch->word_alloc); > > that would have made this hard to get wrong. But that's actually a > bit of a funny interface, because memset is inherently byte-oriented > under the hood. So we are not setting each element to 0x0, but > rather each byte. For a value of 0x0, that is the same thing. But if > you chose, say "0x1", it is not. > > So it would probably have to be limited to something like: > > CLEAR_ARRAY(lm->scratch->words, lm->scratch->word_alloc); > > which I'd guess would cover most memset cases. But this is getting > specific enough that maybe the macro is making things more confusing > rather than less.
I've submitted a v2 that introduces MEMZERO_ARRAY(). I'm curious what the responses on this proposal are?
-- Cheers, Toon