Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 13 Mar 2026 06:58:00 -0700
From:      Cy Schubert <Cy.Schubert@cschubert.com>
To:        Robert Clausecker <fuz@fuz.su>
Cc:        Aymeric Wibo <obiwac@freebsd.org>, src-committers@freebsd.org, dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org
Subject:   Re: git: 4da237aee328 - main - alloca.3: Add entry about defining  VLAs in same block as alloca() to BUGS
Message-ID:  <20260313135800.7355B1A5@slippy.cwsent.com>
In-Reply-To: <abQNdjoZGXJ5caXo@fuz.su>
References:  <69b40cd1.27eba.de1cc3f@gitrepo.freebsd.org>  <abQNdjoZGXJ5caXo@fuz.su>

index | next in thread | previous in thread | raw e-mail

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




home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20260313135800.7355B1A5>