Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 13 Mar 2026 14:13:26 +0100
From:      Robert Clausecker <fuz@fuz.su>
To:        Aymeric Wibo <obiwac@freebsd.org>
Cc:        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:  <abQNdjoZGXJ5caXo@fuz.su>
In-Reply-To: <69b40cd1.27eba.de1cc3f@gitrepo.freebsd.org>

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

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.

Yours,
Robert Clausecker

-- 
()  ascii ribbon campaign - for an encoding-agnostic world
/\  - against html email  - against proprietary attachments


home | help

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