Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250620100455.GA193568@qaa.vinc17.org>
Date: Fri, 20 Jun 2025 12:04:55 +0200
From: Vincent Lefevre <vincent@...c17.net>
To: Paul Eggert <eggert@...ucla.edu>
Cc: Eric Blake <eblake@...hat.com>, Alejandro Colomar <alx@...nel.org>,
	Rich Felker <dalias@...c.org>, enh <enh@...gle.com>,
	Florian Weimer <fweimer@...hat.com>,
	Adhemerval Zanella Netto <adhemerval.zanella@...aro.org>,
	musl@...ts.openwall.com, libc-alpha@...rceware.org,
	Joseph Myers <josmyers@...hat.com>,
	наб <nabijaczleweli@...ijaczleweli.xyz>,
	Robert Seacord <rcseacord@...il.com>,
	Bruno Haible <bruno@...sp.org>, bug-gnulib@....org,
	JeanHeyd Meneide <phdofthehouse@...il.com>,
	Thorsten Glaser <tg@...bsd.de>
Subject: Re: Re: BUG: realloc(p,0) should be consistent with malloc(0)

On 2025-06-19 22:55:32 -0700, Paul Eggert wrote:
> Thanks for the detailed summary. Here are a few more details. In this
> summary "realloc(p,0)" assumes p is nonnull.
> 
> As I understand it:
> 
> (a) These guarantees are for compatibility with glibc 2.2+. In older glibc
> versions realloc(p,0) behaved like (free(p),malloc(0)).
> 
> (b) Ulrich Drepper changed glibc 2.2 realloc(p,0) after Andreas Jaeger told
> him[1] that draft C99 and UNIX98 required realloc(p,0) to free(p).
> Conformance to these standards was the only motivation given for the glibc
> change.

BTW, at that time, the lack of consistency between realloc(...,0)
and malloc(0) was known and not regarded as an issue:

  https://sourceware.org/pipermail/libc-alpha/1999-April/002398.html

> (c) Ulrich's change[2] to glibc was to make realloc(p,0) equivalent to
> (free(p),0). Draft C99 and UNIX98 did not require this, and Ulrich could
> have made realloc(p,0) continue to be equivalent to (free(p),malloc(0)).
[...]

Indeed, at least the N843 C9x draft (August 1998) did not require this.
It had new text, saying:

  If the realloc function returns a null pointer when size is zero and
  ptr is not a null pointer, the object it pointed to has been freed.

There are also some changes for realloc proposed in

  https://www.open-std.org/jtc1/sc22/wg14/www/docs/n868.htm

(Final CD Ballot for FCD 9899), but nothing for the case of size = 0.

-- 
Vincent Lefèvre <vincent@...c17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / Pascaline project (LIP, ENS-Lyon)

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.