From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from zimbra.cs.ucla.edu (zimbra.cs.ucla.edu [131.179.128.68]) by sourceware.org (Postfix) with ESMTPS id BD5BB385800F for ; Sun, 11 Apr 2021 21:42:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org BD5BB385800F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=cs.ucla.edu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=eggert@cs.ucla.edu Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id C97D21600BE for ; Sun, 11 Apr 2021 14:42:23 -0700 (PDT) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id sn3ijCEKTjuR for ; Sun, 11 Apr 2021 14:42:23 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 0B9CF160095 for ; Sun, 11 Apr 2021 14:42:23 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id RYovvRlblOUp for ; Sun, 11 Apr 2021 14:42:22 -0700 (PDT) Received: from [192.168.1.9] (cpe-172-91-119-151.socal.res.rr.com [172.91.119.151]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id DC0151600BE for ; Sun, 11 Apr 2021 14:42:22 -0700 (PDT) To: GNU C Library From: Paul Eggert Subject: Fix REALLOC_ZERO_BYTES_FREES comment Organization: UCLA Computer Science Department Message-ID: Date: Sun, 11 Apr 2021 14:42:22 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------529EB71CE95A3D5FE2D54424" Content-Language: en-US X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 11 Apr 2021 21:42:26 -0000 This is a multi-part message in MIME format. --------------529EB71CE95A3D5FE2D54424 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit While looking into problems with glibc's documentation of malloc/free/etc. I noticed that the comment for REALLOC_ZERO_BYTES_FREES was out of date: its reference to "the C standard" refers to ISO C11, but that compatibility problem has been fixed in C17. I installed the attached commentary fix as obvious. --------------529EB71CE95A3D5FE2D54424 Content-Type: text/x-patch; charset=UTF-8; name="0001-Fix-REALLOC_ZERO_BYTES_FREES-comment-to-match-C17.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-Fix-REALLOC_ZERO_BYTES_FREES-comment-to-match-C17.patch" >From dff9e592b8f74e2e7be015cbee1c0fad3ef96d37 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 11 Apr 2021 14:39:20 -0700 Subject: [PATCH] Fix REALLOC_ZERO_BYTES_FREES comment to match C17 * malloc/malloc.c (REALLOC_ZERO_BYTES_FREES): Update comment to match current C standard. --- malloc/malloc.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/malloc/malloc.c b/malloc/malloc.c index 6640385282..0cd3ba78ca 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -346,10 +346,13 @@ __malloc_assert (const char *assertion, const char *file, unsigned int line, #define REVEAL_PTR(ptr) PROTECT_PTR (&ptr, ptr) /* - REALLOC_ZERO_BYTES_FREES should be set if a call to - realloc with zero bytes should be the same as a call to free. - This is required by the C standard. Otherwise, since this malloc - returns a unique pointer for malloc(0), so does realloc(p, 0). + REALLOC_ZERO_BYTES_FREES controls the behavior of realloc (p, 0) + when p is nonnull. If nonzero, realloc (p, 0) should free p and + return NULL. Otherwise, realloc (p, 0) should do the equivalent + of freeing p and returning what malloc (0) would return. + + ISO C17 says the behavior is implementation-defined here; glibc + follows historical practice and defines it to be nonzero. */ #ifndef REALLOC_ZERO_BYTES_FREES -- 2.27.0 --------------529EB71CE95A3D5FE2D54424--