1
0
mirror of https://github.com/janet-lang/janet synced 2024-09-27 14:48:13 +00:00
Be really sure we don't pass too large of a size to memcpy.
There seem to be some situations where the slotcount and the ua.count
do not match at all, so use the mimimum for copying.
This commit is contained in:
Calvin Rose 2020-05-28 10:47:22 -05:00
parent b33fdc1674
commit fff66649aa
2 changed files with 9 additions and 3 deletions

View File

@ -750,12 +750,14 @@ JanetFuncDef *janetc_pop_funcdef(JanetCompiler *c) {
/* Copy upvalue bitset */
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 = calloc(sizeof(uint32_t), numchunks);
int32_t slotchunks = (def->slotcount + 31) >> 5;
/* numchunks is min of slotchunks and scope->ua.count */
int32_t numchunks = slotchunks > scope->ua.count ? scope->ua.count : slotchunks;
uint32_t *chunks = calloc(sizeof(uint32_t), slotchunks);
if (NULL == chunks) {
JANET_OUT_OF_MEMORY;
}
memcpy(chunks, scope->ua.chunks, sizeof(uint32_t) * scope->ua.count);
memcpy(chunks, scope->ua.chunks, sizeof(uint32_t) * numchunks);
/* 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;

View File

@ -26,6 +26,8 @@
#include "util.h"
#endif
#ifdef JANET_NET
#ifdef JANET_WINDOWS
#include <winsock2.h>
#include <windows.h>
@ -675,3 +677,5 @@ void janet_net_deinit(void) {
WSACleanup();
#endif
}
#endif