public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: GNU C Library <libc-alpha@sourceware.org>
Subject: Fix REALLOC_ZERO_BYTES_FREES comment
Date: Sun, 11 Apr 2021 14:42:22 -0700	[thread overview]
Message-ID: <a22669d1-f2c5-c74e-3bf2-fb518f40d450@cs.ucla.edu> (raw)

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

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.

[-- Attachment #2: 0001-Fix-REALLOC_ZERO_BYTES_FREES-comment-to-match-C17.patch --]
[-- Type: text/x-patch, Size: 1376 bytes --]

From dff9e592b8f74e2e7be015cbee1c0fad3ef96d37 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
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


             reply	other threads:[~2021-04-11 21:42 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-11 21:42 Paul Eggert [this message]
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
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=a22669d1-f2c5-c74e-3bf2-fb518f40d450@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --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).