From nobody Fri Mar 13 13:10:41 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4fXPxL5BQ4z6V5lB for ; Fri, 13 Mar 2026 13:10:46 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R12" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4fXPxL4k4Lz3YXt for ; Fri, 13 Mar 2026 13:10:46 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1773407446; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=cjmysL32HZmImTaKa2HFPmNCMRDl5Zqg2Xxr4140l8o=; b=ntV7mxmnZVo1B8bP//tnkbhA51NNDo8IkdLzQJu/PoA0zAnI7dT3jHBoWx3LWU4o2Y5yTN 59S5DkxMe8bx70TeR1MjWT/9dlWLw+4ptfBCRm2j/mj4uMf31HQ3AcbZpAEBGm1x7ilvwz vEpr3lPy7pDGisvP2FiArON3Y4wc8j1BCb5C+BKMrEzx22dUdCoOyf6I6Y7SeHXONkJF8b x+dDgVfmipeekkqobIIaqifN2NRaFbJ0FO/FvpNd3OC9XLOCj60veDh0/rmH0cfB/58Woa OPBXe5xi1h1S6UeQFG73pprkfQCCpT7kWCwe8NYdBbNn+jX1O9FdpUg/lmICkw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1773407446; a=rsa-sha256; cv=none; b=UhxBy8hjFgQqVDPzQb1MoFKh2ghJQ4+rtpvUo11uiSvLIYIoO5pzhSVt9mfB2m98RS4Qka QF0GI9kELZD36lfLUookjuAcYlU0JLdKSEK5zzkg3sp//rm0iqJxfti/GukqF89enm6gIj DARC4AwwQbkNw+8F7RtdlRDPmZ51fmjsIeemj91QEAu3gi53DDMhVFt5ruKlOksg3xsSKB qedXwhA4qU7kju5V2Nt04ax/nRfVyLzu0Q2JJVlpFjg4RRzIoPqno0PmuKcEwXnPSHigOc oaEVmfm8QCbUZaDn52YOSfTci/ggu8nsTq9rfE4Bqskr+KvQbCI5HRxNhoaMbA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1773407446; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=cjmysL32HZmImTaKa2HFPmNCMRDl5Zqg2Xxr4140l8o=; b=bDT4CWS2LvS5Kmv5BWukpWxSa/3dQ8iPaZ9YTNwO4yTEHLf/ADF03NeSxHslrHVqmW8ue9 VPihmGi3jZ0uICrQINzEbZ55Dzoh1y83W3IB2wCFFfTQJE8ZMRMxKl1X21qUh1Jk6241W9 joGy4tBbdhfByoYaajoGyWmKG2A6dtDbLA53Dg9Ohd8BEmukQZCn8oqXxZluYCTdIExZAC cHgNNKixbn7lIEf9j16xrI3bztOVPCGtRBSaq7sW2uVvcAICT5/7cFbeqpyfrdVazU+sPz nqJvkWqIhBbtim1ryDBw0+flA6/yQqIveuV4Oi9UXdeen18MjmI9fPoUaCVXGw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4fXPxL4GnZzZRr for ; Fri, 13 Mar 2026 13:10:46 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 27eba by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 13 Mar 2026 13:10:41 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Aymeric Wibo Subject: git: 4da237aee328 - main - alloca.3: Add entry about defining VLAs in same block as alloca() to BUGS List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: obiwac X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 4da237aee328f368cd85b659854c4556a39f15ef Auto-Submitted: auto-generated Date: Fri, 13 Mar 2026 13:10:41 +0000 Message-Id: <69b40cd1.27eba.de1cc3f@gitrepo.freebsd.org> The branch main has been updated by obiwac: URL: https://cgit.FreeBSD.org/src/commit/?id=4da237aee328f368cd85b659854c4556a39f15ef commit 4da237aee328f368cd85b659854c4556a39f15ef Author: Aymeric Wibo AuthorDate: 2026-02-19 14:47:06 +0000 Commit: Aymeric Wibo CommitDate: 2026-03-13 13:08:31 +0000 alloca.3: Add entry about defining VLAs in same block as alloca() to BUGS Refer to alloca() as a (builtin) function or macro, as it could be defined as either depending on the compiler. Paragraph about bug comes from Darwin's libc, and example added to illustrate it. Reviewed by: bnovkov Approved by: bnovkov MFC after: 3 days Obtained from: https://github.com/apple-oss-distributions/libc (partially) Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D55370 --- share/man/man3/alloca.3 | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/share/man/man3/alloca.3 b/share/man/man3/alloca.3 index fd88014dbb33..9e905d4487f3 100644 --- a/share/man/man3/alloca.3 +++ b/share/man/man3/alloca.3 @@ -1,5 +1,6 @@ .\" Copyright (c) 1980, 1991, 1993 .\" The Regents of the University of California. All rights reserved. +.\" Copyright (c) 2026 Aymeric Wibo .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions @@ -25,7 +26,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd April 29, 2025 +.Dd February 19, 2026 .Dt ALLOCA 3 .Os .Sh NAME @@ -38,16 +39,14 @@ .Sh DESCRIPTION The .Fn alloca -function -allocates +function or macro allocates .Fa size bytes of space in the stack frame of the caller. This temporary space is automatically freed on return. .Sh RETURN VALUES -The .Fn alloca -function returns a pointer to the beginning of the allocated space. +returns a pointer to the beginning of the allocated space. .Sh SEE ALSO .Xr brk 2 , .Xr calloc 3 , @@ -55,24 +54,20 @@ function returns a pointer to the beginning of the allocated space. .Xr malloc 3 , .Xr realloc 3 .Sh HISTORY -The .Fn alloca -function appeared in +appeared in .At 32v . .\" .Bx ?? . .\" The function appeared in 32v, pwb and pwb.2 and in 3bsd 4bsd .\" The first man page (or link to a man page that I can find at the .\" moment is 4.3... .Sh BUGS -The .Fn alloca -function is machine and compiler dependent; its use is discouraged. .Pp -The .Fn alloca -function is slightly unsafe because it cannot ensure that the pointer +is slightly unsafe because it cannot ensure that the pointer returned points to a valid and usable block of memory. The allocation made may exceed the bounds of the stack, or even go further into other objects in memory, and @@ -81,3 +76,26 @@ cannot determine such an error. 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