Re: git: 4da237aee328 - main - alloca.3: Add entry about defining VLAs in same block as alloca() to BUGS

From: Cy Schubert <Cy.Schubert_at_cschubert.com>
Date: Fri, 13 Mar 2026 13:58:00 UTC
In message <abQNdjoZGXJ5caXo@fuz.su>, Robert Clausecker writes:
> Hi Aymeric,
>
> Am Fri, Mar 13, 2026 at 01:10:41PM +0000 schrieb Aymeric Wibo:
> >  Avoid
> >  .Fn alloca
> >  with large unbounded allocations.
> > +.Pp
> > +The use of C99 variable-length arrays and
> > +.Fn alloca
> > +in the same function will cause the lifetime of
> > +.Fn alloca Ns 's
> > +storage to be limited to the block containing the
> > +.Fn alloca .
> > +For example, in the following snippet,
> > +.Va p Ns 's
> > +lifetime does not extend outside of the block, whereas it would've if
> > +.Va vla
> > +hadn't been defined or had been defined as a fixed-length array:
> > +.Bd -literal -offset indent
> > +char *p;
> > +{
> > +	const int n = 100;
> > +	int vla[n];
> > +	p = alloca(32);
> > +	strcpy(p, "Hello, world!");
> > +	printf("Inside: %s\\n", p); /* Valid. */
> > +}
> > +printf("Outside: %s\\n", p); /* Undefined. */
> > +.Ed
>
> I am unsure if we should document the behaviour of mixing VLAs and
> alloca() in the same function as being defined, as that binds us to
> support it in the future.  I would be a lot more comfortable just
> documenting that behaviour is undefined if the two are combined in
> one function.

Agreed.

>
> Yours,
> Robert Clausecker
>
> -- 
> ()  ascii ribbon campaign - for an encoding-agnostic world
> /\  - against html email  - against proprietary attachments
>


-- 
Cheers,
Cy Schubert <Cy.Schubert@cschubert.com>
FreeBSD UNIX:  <cy@FreeBSD.org>   Web:  https://FreeBSD.org
NTP:           <cy@nwtime.org>    Web:  https://nwtime.org

			e**(i*pi)+1=0