prism_compile.c: Avoid zero length allocation

The constant pool may be empty.
This commit is contained in:
Jean Boussier 2025-04-04 12:25:03 +02:00
parent 135e5bff9a
commit 432e5fa7e4
Notes: git 2025-04-07 10:00:27 +00:00

View file

@ -11053,7 +11053,7 @@ pm_parse_process(pm_parse_result_t *result, pm_node_t *node, VALUE *script_lines
// Now set up the constant pool and intern all of the various constants into
// their corresponding IDs.
scope_node->parser = parser;
scope_node->constants = xcalloc(parser->constant_pool.size, sizeof(ID));
scope_node->constants = parser->constant_pool.size ? xcalloc(parser->constant_pool.size, sizeof(ID)) : NULL;
for (uint32_t index = 0; index < parser->constant_pool.size; index++) {
pm_constant_t *constant = &parser->constant_pool.constants[index];