Re: [PATCH] last-modified: fix bug caused by inproper initialized memory
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Dec 8, 2025, 22:42 UTC
- Message-ID
- <xmqq5xaglhn3.fsf@gitster.g>
- In-Reply-To
- <20251208201501.GA216526@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 15 quoted lines
> git grep 'memset(.*0,.*\* \?sizeof' > > that's looking for memsets of "0" that also multiply by sizeof. Looks > like there are a few: > > add-patch.c: memset(hunk + 1, 0, (splittable_into - 1) * sizeof(*hunk)); > builtin/last-modified.c: memset(lm->scratch->words, 0x0, lm->scratch->word_alloc * sizeof(eword_t)); > compat/simple-ipc/ipc-win32.c: memset(ea, 0, NR_EA * sizeof(EXPLICIT_ACCESS)); > diff-delta.c: memset(hash, 0, hsize * sizeof(*hash)); > hashmap.c: memset(map->table, 0, map->tablesize * sizeof(struct hashmap_entry *)); > pack-revindex.c: memset(pos, 0, BUCKETS * sizeof(*pos)); > > The first one is an oddball, but the other five could use it. So if we > were to do a patch adding MEMZERO_ARRAY(), it would probably make sense > to convert those spots. I'd be OK either way.
Thanks for making an excellent suggestion while I was away from the keyboard ;-)
Between MEMZERO_ARRAY() and CLEAR_ARRAY(), I am on the fence.