BUG: realloc(p,0) should be consistent with malloc(0)
Alejandro Colomar
alx@kernel.org
Thu Jun 19 23:56:49 GMT 2025
Hi Paul,
On Thu, Jun 19, 2025 at 08:07:35PM +0000, Wilco Dijkstra wrote:
> Hi Paul,
>
> > 2. When p is not null, realloc(p,0) frees p, returns NULL, and sets
> > errno=EINVAL. This conforms to both POSIX.1-2017 and POSIX.1-2024.
>
> That's interesting, was POSIX getting the idea of setting errno from AIX perhaps?
>
> However POSIX.1-2024 actually requires that the old block must not be freed
> if errno is set...
Indeed, I have a hard time reading POSIX.1-2024 as allowing realloc(3)
to free the pointer on EINVAL. I don't find it clear, but I'd say it
doesn't allow it because it doesn't say it can do it.
At the very least, it's a very contorted reading of the standard.
Have a lovely day!
Alex
>
> Cheers,
> Wilco
--
<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/20250620/6d600d1c/attachment.sig>
More information about the Libc-alpha
mailing list