diff options
| author | Kevin Newton <kddnewton@gmail.com> | 2024-04-05 14:15:12 -0400 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2024-04-05 19:24:03 +0000 |
| commit | 37ba6927d1bf9d5a0408de479dc030385372b9a2 (patch) | |
| tree | dc40ff0a6f6afaba5b829723c1b281390db741cc | |
| parent | 3b59addaf1d8b1398d0e792803e32e9c0a40fa8c (diff) | |
[ruby/prism] Always calloc the locals resize
https://github.com/ruby/prism/commit/8bbd3fef6f
| -rw-r--r-- | prism/prism.c | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/prism/prism.c b/prism/prism.c index 5d289fe011..52a1dca482 100644 --- a/prism/prism.c +++ b/prism/prism.c @@ -824,21 +824,17 @@ pm_locals_hash(pm_constant_id_t name) { */ static void pm_locals_resize(pm_locals_t *locals) { - pm_local_t *next_locals; uint32_t next_capacity = locals->capacity == 0 ? 4 : (locals->capacity * 2); assert(next_capacity > locals->capacity); - if (next_capacity < PM_LOCALS_HASH_THRESHOLD) { - next_locals = xmalloc(next_capacity * sizeof(pm_local_t)); - if (next_locals == NULL) abort(); + pm_local_t *next_locals = xcalloc(next_capacity, sizeof(pm_local_t)); + if (next_locals == NULL) abort(); + if (next_capacity < PM_LOCALS_HASH_THRESHOLD) { if (locals->size > 0) { memcpy(next_locals, locals->locals, locals->size * sizeof(pm_local_t)); } } else { - next_locals = xcalloc(next_capacity, sizeof(pm_local_t)); - if (next_locals == NULL) abort(); - // If we just switched from a list to a hash, then we need to fill in // the hash values of all of the locals. bool hash_needed = locals->locals[0].hash == 0; |
