BUG: realloc(p,0) is not conforming to C99/C11/C17/POSIX.1-2008

DJ Delorie dj@redhat.com
Thu Oct 17 21:34:49 GMT 2024


Paul Eggert <eggert@cs.ucla.edu> writes:
> As Douglas pointed out, that would run afoul of the longstanding ISO C 
> requirement that each successful call to malloc (without an intervening 
> free) must return a unique pointer.

Sigh.  I wonder how many programs call realloc(ptr,0) *and* require
unique pointers for it.

> If you don't mind that glitch, instead of ((void *) 1) I suggest ((void 
> *) alignof (max_align_t)). Although alignment is not required by the 
> standard, this would be more compatible with what glibc currently does.

I was intentionally trying to make something as useless and likely to
crash as possible, to catch programs that dereference it anyway.



More information about the Libc-alpha mailing list