Realloc's function prototype is void *realloc(void *ptr, size_t size) If we pass realloc a NULL pointer, it's supposed to act just like malloc.
void *new_ptr; new_ptr = malloc(size); if (!new_ptr) { return NULL; // TODO: set errno on failure. }