1
0
mirror of https://github.com/janet-lang/janet synced 2025-11-15 06:47:17 +00:00

Fix some issues found with -fsanitize=undefined

Leave in issues with calling memcpy with size=0. If these
become a problem, will probably add a janet_memcpy as memcpy
is used so much in the code without 0 checks.
This commit is contained in:
Calvin Rose
2019-03-04 11:17:34 -05:00
parent 624be87c97
commit b07adce2b9
6 changed files with 28 additions and 20 deletions

View File

@@ -66,12 +66,16 @@ void janetc_regalloc_clone(JanetcRegisterAllocator *dest, JanetcRegisterAllocato
dest->capacity = src->capacity;
dest->max = src->max;
size = sizeof(uint32_t) * dest->capacity;
dest->chunks = malloc(size);
dest->regtemps = 0;
if (!dest->chunks) {
JANET_OUT_OF_MEMORY;
if (size) {
dest->chunks = malloc(size);
if (!dest->chunks) {
JANET_OUT_OF_MEMORY;
}
memcpy(dest->chunks, src->chunks, size);
} else {
dest->chunks = NULL;
}
memcpy(dest->chunks, src->chunks, size);
}
/* Allocate one more chunk in chunks */