Handling C2Y zero-length operations on null pointers
Alejandro Colomar
alx@kernel.org
Sun Dec 1 17:28:16 GMT 2024
> > And get clarified the qsort/bsearch cases whether it is about just
> > nmemb == 0 or nmemb * size == 0.
>
> C does not support zero-sized objects, so that's something for us to
> figure out on our own. We can treat size == 0 as invalid because the
> functions can't work, as they use pointers for the comparison function
> and not array indices.
Hi Florian,
This is not really true. ISO C claims to not support 0-sized objects,
but then allows malloc(0) to return non-null, and
memcpy(malloc(0), malloc(0), 0);
has always been fully-complying in platforms like glibc, where malloc(0)
returns non-NULL.
Have a lovely day!
Alex
--
<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://gcc.gnu.org/pipermail/gcc/attachments/20241201/1449f7fe/attachment.sig>
More information about the Gcc
mailing list