xcalloc wraps around a call to calloc, and then checks
the pointer returned. However if calloc is called with
either elements or element size set to 0. The return
value is implementation defined.
"If either nelem or elsize is 0, then either a null pointer
or a unique pointer value that can be successfully
passed to free() shall be returned. "
On some platforms, the tests will fail because it thinks
the calloc of 0 elements returned NULL, which is not an
The only portable way to detect the error condition is to
check the errno value to see if it ENOMEM.
Log in to post a comment.