From 057ba8a4e15003d65815018a8dc5648807f83327 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Thu, 21 May 2020 01:30:11 -0500 Subject: [PATCH] Fixes #409 Use the correct count in a memcpy. --- src/core/compile.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/compile.c b/src/core/compile.c index 00c4dccd..88d9b7a3 100644 --- a/src/core/compile.c +++ b/src/core/compile.c @@ -751,11 +751,11 @@ JanetFuncDef *janetc_pop_funcdef(JanetCompiler *c) { if (scope->ua.count) { /* Number of u32s we need to create a bitmask for all slots */ int32_t numchunks = (def->slotcount + 31) >> 5; - uint32_t *chunks = malloc(sizeof(uint32_t) * numchunks); + uint32_t *chunks = calloc(sizeof(uint32_t), numchunks); if (NULL == chunks) { JANET_OUT_OF_MEMORY; } - memcpy(chunks, scope->ua.chunks, sizeof(uint32_t) * numchunks); + memcpy(chunks, scope->ua.chunks, sizeof(uint32_t) * scope->ua.count); /* Register allocator preallocates some registers [240-255, high 16 bits of chunk index 7], we can ignore those. */ if (scope->ua.count > 7) chunks[7] &= 0xFFFFU; def->closure_bitset = chunks;