Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/2195773/?format=api
{ "id": 2195773, "url": "http://patchwork.ozlabs.org/api/patches/2195773/?format=api", "web_url": "http://patchwork.ozlabs.org/project/glibc/patch/20260211201815.82913-4-eggert@cs.ucla.edu/", "project": { "id": 41, "url": "http://patchwork.ozlabs.org/api/projects/41/?format=api", "name": "GNU C Library", "link_name": "glibc", "list_id": "libc-alpha.sourceware.org", "list_email": "libc-alpha@sourceware.org", "web_url": "", "scm_url": "", "webscm_url": "", "list_archive_url": "", "list_archive_url_format": "", "commit_url_format": "" }, "msgid": "<20260211201815.82913-4-eggert@cs.ucla.edu>", "list_archive_url": null, "date": "2026-02-11T20:17:36", "name": "[v2,3/4] Say malloc (0) != NULL is now common; resection", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "afc5bb43ab08338fdf4315cb76a394d1db5bcf3a", "submitter": { "id": 4434, "url": "http://patchwork.ozlabs.org/api/people/4434/?format=api", "name": "Paul Eggert", "email": "eggert@CS.UCLA.EDU" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/glibc/patch/20260211201815.82913-4-eggert@cs.ucla.edu/mbox/", "series": [ { "id": 491904, "url": "http://patchwork.ozlabs.org/api/series/491904/?format=api", "web_url": "http://patchwork.ozlabs.org/project/glibc/list/?series=491904", "date": "2026-02-11T20:17:33", "name": "malloc doc fixes for alignment", "version": 2, "mbox": "http://patchwork.ozlabs.org/series/491904/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2195773/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2195773/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org>", "X-Original-To": [ "incoming@patchwork.ozlabs.org", "libc-alpha@sourceware.org" ], "Delivered-To": [ "patchwork-incoming@legolas.ozlabs.org", "libc-alpha@sourceware.org" ], "Authentication-Results": [ "legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=cs.ucla.edu header.i=@cs.ucla.edu header.a=rsa-sha256\n header.s=9D0B346E-2AEB-11ED-9476-E14B719DCE6C header.b=TdyrUvYm;\n\tdkim-atps=neutral", "legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org\n (client-ip=2620:52:6:3111::32; helo=vm01.sourceware.org;\n envelope-from=libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org;\n receiver=patchwork.ozlabs.org)", "sourceware.org;\n\tdkim=pass (2048-bit key,\n unprotected) header.d=cs.ucla.edu header.i=@cs.ucla.edu header.a=rsa-sha256\n header.s=9D0B346E-2AEB-11ED-9476-E14B719DCE6C header.b=TdyrUvYm", "sourceware.org;\n dmarc=pass (p=none dis=none) header.from=cs.ucla.edu", "sourceware.org; spf=pass smtp.mailfrom=cs.ucla.edu", "server2.sourceware.org;\n arc=none smtp.remote-ip=131.179.128.66", "mail.cs.ucla.edu (amavis); dkim=pass (2048-bit key)\n header.d=cs.ucla.edu" ], "Received": [ "from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fB8wr4Xy0z1xpY\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 12 Feb 2026 07:22:04 +1100 (AEDT)", "from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 700914BA23D6\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 11 Feb 2026 20:22:02 +0000 (GMT)", "from mail.cs.ucla.edu (mail.cs.ucla.edu [131.179.128.66])\n by sourceware.org (Postfix) with ESMTPS id 182224BA2E14\n for <libc-alpha@sourceware.org>; Wed, 11 Feb 2026 20:18:35 +0000 (GMT)", "from localhost (localhost [127.0.0.1])\n by mail.cs.ucla.edu (Postfix) with ESMTP id 620583C014088;\n Wed, 11 Feb 2026 12:18:34 -0800 (PST)", "from mail.cs.ucla.edu ([127.0.0.1])\n by localhost (mail.cs.ucla.edu [127.0.0.1]) (amavis, port 10032) with ESMTP\n id JkCcXwR1SyFl; Wed, 11 Feb 2026 12:18:34 -0800 (PST)", "from localhost (localhost [127.0.0.1])\n by mail.cs.ucla.edu (Postfix) with ESMTP id 3B3A23C0149E2;\n Wed, 11 Feb 2026 12:18:34 -0800 (PST)", "from mail.cs.ucla.edu ([127.0.0.1])\n by localhost (mail.cs.ucla.edu [127.0.0.1]) (amavis, port 10026) with ESMTP\n id AtsnpMoxdGWH; Wed, 11 Feb 2026 12:18:34 -0800 (PST)", "from wing.home (47-154-25-30.fdr01.snmn.ca.ip.frontiernet.net\n [47.154.25.30])\n by mail.cs.ucla.edu (Postfix) with ESMTPSA id 1F8B23C014088;\n Wed, 11 Feb 2026 12:18:34 -0800 (PST)" ], "DKIM-Filter": [ "OpenDKIM Filter v2.11.0 sourceware.org 700914BA23D6", "OpenDKIM Filter v2.11.0 sourceware.org 182224BA2E14", "OpenDKIM Filter v2.10.3 mail.cs.ucla.edu 3B3A23C0149E2" ], "DMARC-Filter": "OpenDMARC Filter v1.4.2 sourceware.org 182224BA2E14", "ARC-Filter": "OpenARC Filter v1.0.0 sourceware.org 182224BA2E14", "ARC-Seal": "i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1770841120; cv=none;\n b=tWs0RWed0gR686b4LwdZiuBvhdO0HCetfMkGjMKiBiE9mefyzixISdK0dJY4PtAQ1+HUO5Rmgysp+AohQLwW7ABjQ4zVdZ/NMKmrpGWj2lm9qLKnAd8FCqWYMaQHnxOYJl4nPk9yl2mzwN/YkQ8ubwX+Qzq8TeO2itqFcqdQ8xc=", "ARC-Message-Signature": "i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1770841120; c=relaxed/simple;\n bh=Ncl0k8TsyJdWbc6sX/MU6vxppuwA5Kp1s8akaG0BmrM=;\n h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version;\n b=VfALGtzWhgt7pF9sicGSViQu+SCsCR5xZyWhPNhXGpC8YrqBMJ5YgdugX5y93UUOI/nF9favr4M9USSu0/eZvz1V62NNDhbpU4VHc/wxAYYLzVtahJojcb1JVlq+tF1D5JRGVjPnFI4ebqO0prnTl+tv3Q2MOOIdf/5mMYEsRbk=", "ARC-Authentication-Results": "i=1; server2.sourceware.org", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=cs.ucla.edu;\n s=9D0B346E-2AEB-11ED-9476-E14B719DCE6C; t=1770841114;\n bh=mZ7uWJ+hPvTHUm+fFrKINF7Voizvv3zBYi39sZ0RXf8=;\n h=From:To:Date:Message-ID:MIME-Version;\n b=TdyrUvYmZBIf85nYRxqki7V9FR2Vk93GR7xKRy4InuvgpoGym/jUH5Lo+41uWVSr/\n vbuihG2YUaMUtYxV8PZkVickDApLOGe9DKk7XBrC2BtlgaCzmVxLGWuYtnO4UkZm7K\n JjjvQXQdASpNYLCG7NvwS5gTncX7Lld2lieplRsOWUZDsCZf/oZfe187PzuqEqhtgm\n cK6MFZ6eHKiuq5Sd5qzIeFjmCi/5ho4R8U252sCayIxklqy5T7DbpoFikW8uGGzH+r\n o5WLYGFl4lVplCL9LCZb7ECIvd5RtYDfm8I33EfCZuQhIte9Z2XfVgAtOYxZ3pmd56\n nRa6s5IxEtBtA==", "X-Virus-Scanned": "amavis at mail.cs.ucla.edu", "From": "Paul Eggert <eggert@cs.ucla.edu>", "To": "libc-alpha@sourceware.org", "Cc": "Paul Eggert <eggert@cs.ucla.edu>", "Subject": "[PATCH v2 3/4] Say malloc (0) != NULL is now common; resection", "Date": "Wed, 11 Feb 2026 12:17:36 -0800", "Message-ID": "<20260211201815.82913-4-eggert@cs.ucla.edu>", "X-Mailer": "git-send-email 2.51.0", "In-Reply-To": "<20260211201815.82913-1-eggert@cs.ucla.edu>", "References": "<20260211201815.82913-1-eggert@cs.ucla.edu>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "quoted-printable", "X-BeenThere": "libc-alpha@sourceware.org", "X-Mailman-Version": "2.1.30", "Precedence": "list", "List-Id": "Libc-alpha mailing list <libc-alpha.sourceware.org>", "List-Unsubscribe": "<https://sourceware.org/mailman/options/libc-alpha>,\n <mailto:libc-alpha-request@sourceware.org?subject=unsubscribe>", "List-Archive": "<https://sourceware.org/pipermail/libc-alpha/>", "List-Post": "<mailto:libc-alpha@sourceware.org>", "List-Help": "<mailto:libc-alpha-request@sourceware.org?subject=help>", "List-Subscribe": "<https://sourceware.org/mailman/listinfo/libc-alpha>,\n <mailto:libc-alpha-request@sourceware.org?subject=subscribe>", "Errors-To": "libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org" }, "content": "* manual/memory.texi (Portable Allocation):\nNew section, split off from Malloc Examples.\nSay that almost every system follows glibc's example\nin having successful malloc (0) return non-null;\nAIX is the only exception nowadays.\nDocument fundamental alignment portability.\n---\n manual/memory.texi | 88 +++++++++++++++++++++++++++++++++++-----------\n 1 file changed, 68 insertions(+), 20 deletions(-)", "diff": "diff --git a/manual/memory.texi b/manual/memory.texi\nindex dab2592ac3..55cb92a0bd 100644\n--- a/manual/memory.texi\n+++ b/manual/memory.texi\n@@ -318,6 +318,7 @@ any time (or never).\n @menu\n * Basic Allocation:: Simple use of @code{malloc}.\n * Malloc Examples:: Examples of @code{malloc}. @code{xmalloc}.\n+* Portable Allocation:: Portable use of @code{malloc}.\n * Freeing after Malloc:: Use @code{free} to free a block you\n \t\t\t\t got with @code{malloc}.\n * Changing Block Size:: Use @code{realloc} to make a block\n@@ -669,19 +670,23 @@ contents of another block. If you have already allocated a block and\n discover you want it to be bigger, use @code{realloc} (@pxref{Changing\n Block Size}).\n \n-@strong{Portability Notes:}\n+@node Portable Allocation\n+@subsubsection Portable Memory Allocation\n+\n+More care is needed when allocating memory in\n+code intended to run on both GNU and non-GNU systems,\n+or when a non-GNU replacement allocator is used (@pxref{Replacing malloc}).\n+When storage size is small or outlandishly large,\n+or when storage is allocated for a less-common type,\n+the POSIX and ISO C standards permit multiple behaviors.\n \n @itemize @bullet\n @item\n-In @theglibc{}, a successful @code{malloc (0)}\n-returns a non-null pointer to a newly allocated size-zero block;\n-other implementations may return @code{NULL} instead.\n-POSIX and the ISO C standard allow both behaviors.\n-\n-@item\n-In implementations other than @theglibc{}, a non-null pointer returned\n-by @code{malloc (@var{size})} is guaranteed to be aligned only for\n-fundamentally-aligned objects of size at most @code{max (@var{size}, 1)}.\n+In @theglibc{} and most other systems, a successful @code{malloc (0)}\n+returns a non-null pointer to a newly allocated size-zero block.\n+However, in IBM AIX a successful @code{malloc (0)} returns a null pointer,\n+and this breaks common code such as the implementation of @code{xmalloc}\n+given in this manual (@pxref{Malloc Examples}).\n \n @item\n In @theglibc{}, a failed @code{malloc} call sets @code{errno},\n@@ -693,6 +698,44 @@ In @theglibc{}, @code{malloc} always fails when @var{size} exceeds\n @code{PTRDIFF_MAX}, to avoid problems with programs that subtract\n pointers or use signed indexes. Other implementations may succeed in\n this case, leading to undefined behavior later.\n+\n+@item\n+In other implementations, a non-null pointer returned\n+by @code{malloc (@var{size})} is guaranteed to be aligned only for\n+fundamentally-aligned objects of size at most @code{max (@var{size}, 1)}.\n+This may be less than the alignment guaranteed by @theglibc{}.\n+\n+@item\n+Although @theglibc{}'s headers define only types with fundamental alignment,\n+the C and POSIX standards require only the following types\n+(if available) to have fundamental alignment:\n+\n+@quotation\n+@code{char};\n+all integer types (including @code{bool});\n+@code{float}, @code{double}, @code{long double};\n+@code{_Decimal32}, @code{_Decimal64}, @code{_Decimal128};\n+@code{float _Complex}, @code{double _Complex}, @code{long double _Complex};\n+all enumerated types;\n+all pointer types;\n+all array types whose element types have fundamental alignment;\n+all struct and union types whose element types all have\n+fundamental alignment and that lack stricter alignment specifiers;\n+@code{va_list} (in @code{<stdarg.h>});\n+@code{fpos_t} (in @code{<stdio.h>});\n+@code{cnd_t}, @code{thrd_t}, @code{tss_t}, @code{mtx_t}, @code{once_flag}\n+(in @code{<threads.h>});\n+@code{mbstate_t} (in @code{<wchar.h>}).\n+@end quotation\n+\n+@noindent\n+In theory, portable code should not use @code{malloc} to\n+allocate storage containing types not in this list;\n+it should instead use functions like @code{aligned_alloc}.\n+In practice, though, other implementations generally follow\n+@theglibc{}'s lead and define only types with fundamental alignment,\n+and it is generally portable to use @code{malloc} to allocate objects\n+with types defined by the C library.\n @end itemize\n \n @node Freeing after Malloc\n@@ -876,6 +919,8 @@ is left undisturbed.\n Any non-null pointer returned by @code{realloc} satisfies the same\n alignment restrictions as a similar pointer returned by @code{malloc}\n with the same size.\n+Any special alignment created by @code{aligned_alloc}\n+and similar functions is lost after @code{realloc}.\n @end deftypefun\n \n @deftypefun {void *} reallocarray (void *@var{ptr}, size_t @var{nmemb}, size_t @var{size})\n@@ -893,6 +938,13 @@ returning a null pointer, and leaving the original block unchanged.\n @code{reallocarray} should be used instead of @code{realloc} when the new size\n of the allocated block is the result of a multiplication that might overflow.\n \n+In @theglibc{}, the vector is aligned the same way that @code{malloc}\n+aligns its returned values. In other implementations, it is merely\n+aligned suitably for any array of fundamentally-aligned elements each\n+with size at most @code{max (@var{size}, 1)}.\n+Any special alignment created by @code{aligned_alloc}\n+and similar functions is lost after @code{reallocarray}.\n+\n This function was originally derived from OpenBSD 5.6, but was added in\n POSIX.1-2024.\n @end deftypefun\n@@ -987,15 +1039,9 @@ is declared in @file{stdlib.h}.\n @c chunk_is_mmapped dup ok\n @c MALLOC_ZERO ok\n @c memset dup ok\n-This function allocates a block long enough to contain a vector of\n-@var{count} elements, each of size @var{eltsize}. Its contents are\n-cleared to zero before @code{calloc} returns.\n-\n-In @theglibc{}, the vector is aligned the same way that @code{malloc}\n-aligns its returned values. In other implementations, it is merely\n-aligned suitably for any array of fundamentally-aligned elements each\n-with size at most @code{max (@var{size}, 1)}.\n-\n+This function allocates a zeroed vector. It acts like\n+@code{reallocarray (NULL, @var{count}, @var{eltsize})} except that the\n+vector's contents are cleared to zero before @code{calloc} returns.\n @end deftypefun\n \n You could define @code{calloc} as follows:\n@@ -1927,7 +1973,9 @@ functions (that is, all the functions used by the application,\n failures, and, at run time, to heap corruption and application crashes.\n Replacement functions should implement the behavior documented for\n their counterparts in @theglibc{}; for example, the replacement\n-@code{free} should also preserve @code{errno}.\n+@code{malloc} should return a null pointer only when failing\n+and should return pointers aligned to @code{alignof (max_align_t)},\n+and the replacement @code{free} should preserve @code{errno}.\n \n The minimum set of functions which has to be provided by a custom\n @code{malloc} is given in the table below.\n", "prefixes": [ "v2", "3/4" ] }