Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow xcalloc() to return NULL when size is 0 for portability
According to the calloc(3) man page, when nmemb or size is 0, calloc() can either return NULL or a unique pointer that can be passed to free(). https://manpages.org/calloc/3 While gcc (13.3.0) and clang (15.0.7), in my environment, return *a unique pointer* in this case, mruby's `mrb_calloc` returns *NULL*. https://github.com/mruby/mruby/blob/3.3.0/src/gc.c#L253 Since `pm_constant_pool_init()` is commonly called with capacity=0 during normal operation of Prism, `xcalloc()` needs to handle NULL returns to integrate with mruby. Per free()'s and realloc()'s specification, passing NULL pointer is a valid operation, so this change should be safe.
- Loading branch information