From: Jeff King Date: Fri, 15 May 2026 19:08:18 GMT Subject: Re: [PATCH] evaluate the second argument of ALLOC_GROW only once Message-ID: <20260515190818.GA98370@coredump.intra.peff.net> In-Reply-To: <323f5677-301b-4d7a-b552-6606597c2b1f@web.de> On Fri, May 15, 2026 at 08:16:50PM +0200, René Scharfe wrote: > + size_t alloc_grow_new_alloc_; \ > + if (st_alloc_nr((nr), (alloc), &alloc_grow_new_alloc_)) { \ > + alloc = alloc_grow_new_alloc_; \ > + REALLOC_ARRAY(x, alloc_grow_new_alloc_); \ > } \ What happens if a caller passes in an argument that isn't a size_t? We'll check for overflow in the size_t space, and then truncate it when we assign to alloc, I think. I think we generally try to hold allocations in size_t these days, but I'd be surprised if there weren't a few "int" holdouts. Grepping around, alloc_node() seems to be an example. BTW, non-size_t arguments nullifies my earlier hand-waving around "nr + 1 overflowing implies we've filled up the address space". But we are still protected in the existing code by the: if (alloc_nr(alloc) < (nr)) alloc = (nr); logic. But with your patch, that all happens in the size_t space, so I think it would actually introduce possible array overflows when the caller is using a smaller type. -Peff