Skip to content

Commit 8bbd3fe

Browse files
committed
Always calloc the locals resize
1 parent 91f8c0c commit 8bbd3fe

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

src/prism.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -824,21 +824,17 @@ pm_locals_hash(pm_constant_id_t name) {
824824
*/
825825
static void
826826
pm_locals_resize(pm_locals_t *locals) {
827-
pm_local_t *next_locals;
828827
uint32_t next_capacity = locals->capacity == 0 ? 4 : (locals->capacity * 2);
829828
assert(next_capacity > locals->capacity);
830829

831-
if (next_capacity < PM_LOCALS_HASH_THRESHOLD) {
832-
next_locals = xmalloc(next_capacity * sizeof(pm_local_t));
833-
if (next_locals == NULL) abort();
830+
pm_local_t *next_locals = xcalloc(next_capacity, sizeof(pm_local_t));
831+
if (next_locals == NULL) abort();
834832

833+
if (next_capacity < PM_LOCALS_HASH_THRESHOLD) {
835834
if (locals->size > 0) {
836835
memcpy(next_locals, locals->locals, locals->size * sizeof(pm_local_t));
837836
}
838837
} else {
839-
next_locals = xcalloc(next_capacity, sizeof(pm_local_t));
840-
if (next_locals == NULL) abort();
841-
842838
// If we just switched from a list to a hash, then we need to fill in
843839
// the hash values of all of the locals.
844840
bool hash_needed = locals->locals[0].hash == 0;

0 commit comments

Comments
 (0)