void *ptr = malloc(size); memset(ptr, 0, size); return ptr; } Note that this doesn't check for overflow in nelem * elsize, which is actually required by the spec.
void *new_ptr; new_ptr = malloc(size); if (!new_ptr) { return NULL; // TODO: set errno on failure. }