From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id A3E843835429 for ; Mon, 12 Apr 2021 07:53:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A3E843835429 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-509-H404nY0GM7-l3f4b4cw6wg-1; Mon, 12 Apr 2021 03:53:28 -0400 X-MC-Unique: H404nY0GM7-l3f4b4cw6wg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 595448030B5; Mon, 12 Apr 2021 07:53:27 +0000 (UTC) Received: from oldenburg.str.redhat.com (ovpn-112-148.ams2.redhat.com [10.36.112.148]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C73075D720; Mon, 12 Apr 2021 07:53:25 +0000 (UTC) From: Florian Weimer To: Paul Eggert Cc: Paul Zimmermann , libc-alpha@sourceware.org Subject: Re: Fix REALLOC_ZERO_BYTES_FREES comment References: <8735vwows4.fsf@oldenburg.str.redhat.com> Date: Mon, 12 Apr 2021 09:53:35 +0200 In-Reply-To: (Paul Eggert's message of "Mon, 12 Apr 2021 00:48:02 -0700") Message-ID: <87eefgndkw.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, 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: Mon, 12 Apr 2021 07:53:32 -0000 * Paul Eggert: > 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. > */ I think this is a really good explanation of the situation. Thanks. Florian