1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-24 17:27:18 +00:00
Use the correct count in a memcpy.
This commit is contained in:
Calvin Rose 2020-05-21 01:30:11 -05:00
parent 677737d345
commit 057ba8a4e1

View File

@ -751,11 +751,11 @@ JanetFuncDef *janetc_pop_funcdef(JanetCompiler *c) {
if (scope->ua.count) { if (scope->ua.count) {
/* Number of u32s we need to create a bitmask for all slots */ /* Number of u32s we need to create a bitmask for all slots */
int32_t numchunks = (def->slotcount + 31) >> 5; 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) { if (NULL == chunks) {
JANET_OUT_OF_MEMORY; 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. */ /* 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; if (scope->ua.count > 7) chunks[7] &= 0xFFFFU;
def->closure_bitset = chunks; def->closure_bitset = chunks;