public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: Paul Zimmermann <Paul.Zimmermann@inria.fr>,
	Florian Weimer <fweimer@redhat.com>
Cc: libc-alpha@sourceware.org
Subject: Re: Fix REALLOC_ZERO_BYTES_FREES comment
Date: Mon, 12 Apr 2021 00:48:02 -0700	[thread overview]
Message-ID: <a7da171a-5796-5859-6d08-08f229840579@cs.ucla.edu> (raw)
In-Reply-To: <mwim4st47n.fsf@tomate.loria.fr>

[-- Attachment #1: Type: text/plain, Size: 301 bytes --]

On 4/11/21 11:19 PM, Paul Zimmermann wrote:
> Why not simply the following?
> 
> "Otherwise, realloc (p, 0) should free p and return what malloc (0) would."

Thanks, that is better wording. I installed the attached comment patch, 
which also attempts to address the other points you and Florian made.

[-- Attachment #2: 0001-Further-fixes-for-REALLOC_ZERO_BYTES_FREES-comment.patch --]
[-- Type: text/x-patch, Size: 1552 bytes --]

From 9f1bed18f9466ac886addb2f79d8e4c52fb65eb5 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Mon, 12 Apr 2021 00:33:15 -0700
Subject: [PATCH] Further fixes for REALLOC_ZERO_BYTES_FREES comment

* malloc/malloc.c (REALLOC_ZERO_BYTES_FREES): Improve comment further.
---
 malloc/malloc.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/malloc/malloc.c b/malloc/malloc.c
index 0cd3ba78ca..e2d7b1b583 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -346,13 +346,14 @@ __malloc_assert (const char *assertion, const char *file, unsigned int line,
 #define REVEAL_PTR(ptr)  PROTECT_PTR (&ptr, ptr)
 
 /*
-  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.
+  The REALLOC_ZERO_BYTES_FREES macro controls the behavior of realloc (p, 0)
+  when p is nonnull.  If the macro is nonzero, the realloc call returns NULL;
+  otherwise, the call returns what malloc (0) would.  In either case,
+  p is freed.  Glibc uses a nonzero REALLOC_ZERO_BYTES_FREES, which
+  implements common historical practice.
+
+  ISO C17 says the realloc call has implementation-defined behavior,
+  and it might not even free p.
 */
 
 #ifndef REALLOC_ZERO_BYTES_FREES
-- 
2.27.0


  reply	other threads:[~2021-04-12  7:48 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-11 21:42 Paul Eggert
2021-04-12  6:05 ` Paul Zimmermann
2021-04-12  6:13   ` Florian Weimer
2021-04-12  6:19     ` Paul Zimmermann
2021-04-12  7:48       ` Paul Eggert [this message]
2021-04-12  7:53         ` Florian Weimer
2021-04-12 19:44         ` DJ Delorie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a7da171a-5796-5859-6d08-08f229840579@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=Paul.Zimmermann@inria.fr \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).