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

Alejandro Colomar alx@kernel.org
Thu Oct 17 22:03:06 GMT 2024


Hi DJ,

On Thu, Oct 17, 2024 at 02:39:22PM GMT, DJ Delorie wrote:
> 
> Just thinking outside the box...
> 
> Would we be more compliant if glibc's malloc et al have an internal
> "zero length chunk" with an address of (size_t)1 ?

glibc's current malloc(0) is just fine, and perfectly compliant.  I
don't see why it should be changed.  A non-unique pointer like you're
suggesting would reduce the leaks, but any programs that leak should be
fixed.  Avoiding the leaks with this implementation might hide the bugs,
which would make them more difficult to spot, and thus result in a worse
system.

Have a lovely day!
Alex

>  We could return this
> instead of NULL when we want to return NULL for zero-length chunks, but
> otherwise treat that as NULL internally.
> 
> It would give applications a non-NULL pointer to memory they still can't
> access without a fault...
> 

-- 
<https://www.alejandro-colomar.es/>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20241018/13c17905/attachment-0001.sig>


More information about the Libc-alpha mailing list