mirror of
https://github.com/ruby/ruby.git
synced 2026-01-29 05:24:23 +00:00
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()`. While gcc and clang typically return a unique pointer, mruby's `mrb_calloc()` returns NULL in this case. Since `pm_constant_pool_init()` is commonly called with capacity=0 during normal operation of Prism, explicitly handle this case by setting `list->ids` to NULL when capacity is 0. This approach is portable across different calloc implementations and avoids potential issues with mruby's allocation behavior. This maintains compatibility with `free()` and `realloc()`, as passing NULL pointers to these functions is explicitly allowed by their specifications. https://github.com/ruby/prism/commit/1c32252df7