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 <vinc...@vinc17.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)

Reply via email to