mirror of
https://github.com/janet-lang/janet
synced 2025-06-06 16:44:12 +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:
parent
624be87c97
commit
b07adce2b9
@ -89,8 +89,9 @@ static void janetc_loadconst(JanetCompiler *c, Janet k, int32_t reg) {
|
|||||||
int32_t i = (int32_t) dval;
|
int32_t i = (int32_t) dval;
|
||||||
if (dval != i || !(dval >= INT16_MIN && dval <= INT16_MAX))
|
if (dval != i || !(dval >= INT16_MIN && dval <= INT16_MAX))
|
||||||
goto do_constant;
|
goto do_constant;
|
||||||
|
uint32_t iu = (uint32_t)i;
|
||||||
janetc_emit(c,
|
janetc_emit(c,
|
||||||
(i << 16) |
|
(iu << 16) |
|
||||||
(reg << 8) |
|
(reg << 8) |
|
||||||
JOP_LOAD_INTEGER);
|
JOP_LOAD_INTEGER);
|
||||||
break;
|
break;
|
||||||
|
@ -529,15 +529,18 @@ static int32_t readint(UnmarshalState *st, const uint8_t **atdata) {
|
|||||||
ret = *data++;
|
ret = *data++;
|
||||||
} else if (*data < 192) {
|
} else if (*data < 192) {
|
||||||
MARSH_EOS(st, data + 1);
|
MARSH_EOS(st, data + 1);
|
||||||
ret = ((data[0] & 0x3F) << 8) + data[1];
|
uint32_t uret = ((data[0] & 0x3F) << 8) + data[1];
|
||||||
ret = ((ret << 18) >> 18);
|
/* Sign extend 18 MSBs */
|
||||||
|
uret |= (uret >> 13) ? 0xFFFFC000 : 0;
|
||||||
|
ret = (int32_t)uret;
|
||||||
data += 2;
|
data += 2;
|
||||||
} else if (*data == LB_INTEGER) {
|
} else if (*data == LB_INTEGER) {
|
||||||
MARSH_EOS(st, data + 4);
|
MARSH_EOS(st, data + 4);
|
||||||
ret = ((int32_t)(data[1]) << 24) |
|
uint32_t ui = ((uint32_t)(data[1]) << 24) |
|
||||||
((int32_t)(data[2]) << 16) |
|
((uint32_t)(data[2]) << 16) |
|
||||||
((int32_t)(data[3]) << 8) |
|
((uint32_t)(data[3]) << 8) |
|
||||||
(int32_t)(data[4]);
|
(uint32_t)(data[4]);
|
||||||
|
ret = (int32_t)ui;
|
||||||
data += 5;
|
data += 5;
|
||||||
} else {
|
} else {
|
||||||
janet_panicf("expected integer, got byte %x at index %d",
|
janet_panicf("expected integer, got byte %x at index %d",
|
||||||
@ -970,11 +973,12 @@ static const uint8_t *unmarshal_one(
|
|||||||
case LB_INTEGER:
|
case LB_INTEGER:
|
||||||
/* Long integer */
|
/* Long integer */
|
||||||
MARSH_EOS(st, data + 4);
|
MARSH_EOS(st, data + 4);
|
||||||
*out = janet_wrap_integer(
|
uint32_t ui = ((uint32_t)(data[4])) |
|
||||||
(data[4]) |
|
((uint32_t)(data[3]) << 8) |
|
||||||
(data[3] << 8) |
|
((uint32_t)(data[2]) << 16) |
|
||||||
(data[2] << 16) |
|
((uint32_t)(data[1]) << 24);
|
||||||
(data[1] << 24));
|
int32_t si = (int32_t)ui;
|
||||||
|
*out = janet_wrap_integer(si);
|
||||||
return data + 5;
|
return data + 5;
|
||||||
case LB_REAL:
|
case LB_REAL:
|
||||||
/* Real */
|
/* Real */
|
||||||
|
@ -49,7 +49,7 @@ static const uint32_t symchars[8] = {
|
|||||||
/* Check if a character is a valid symbol character
|
/* Check if a character is a valid symbol character
|
||||||
* symbol chars are A-Z, a-z, 0-9, or one of !$&*+-./:<=>@\^_~| */
|
* symbol chars are A-Z, a-z, 0-9, or one of !$&*+-./:<=>@\^_~| */
|
||||||
static int is_symbol_char(uint8_t c) {
|
static int is_symbol_char(uint8_t c) {
|
||||||
return symchars[c >> 5] & (1 << (c & 0x1F));
|
return symchars[c >> 5] & ((uint32_t)1 << (c & 0x1F));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Validate some utf8. Useful for identifiers. Only validates
|
/* Validate some utf8. Useful for identifiers. Only validates
|
||||||
|
@ -66,12 +66,16 @@ void janetc_regalloc_clone(JanetcRegisterAllocator *dest, JanetcRegisterAllocato
|
|||||||
dest->capacity = src->capacity;
|
dest->capacity = src->capacity;
|
||||||
dest->max = src->max;
|
dest->max = src->max;
|
||||||
size = sizeof(uint32_t) * dest->capacity;
|
size = sizeof(uint32_t) * dest->capacity;
|
||||||
dest->chunks = malloc(size);
|
|
||||||
dest->regtemps = 0;
|
dest->regtemps = 0;
|
||||||
if (!dest->chunks) {
|
if (size) {
|
||||||
JANET_OUT_OF_MEMORY;
|
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 */
|
/* Allocate one more chunk in chunks */
|
||||||
|
@ -566,8 +566,8 @@ static JanetSlot janetc_while(JanetFopts opts, int32_t argn, const Janet *argv)
|
|||||||
|
|
||||||
/* Calculate jumps */
|
/* Calculate jumps */
|
||||||
labeld = janet_v_count(c->buffer);
|
labeld = janet_v_count(c->buffer);
|
||||||
if (!infinite) c->buffer[labelc] |= (labeld - labelc) << 16;
|
if (!infinite) c->buffer[labelc] |= (uint32_t)(labeld - labelc) << 16;
|
||||||
c->buffer[labeljt] |= (labelwt - labeljt) << 8;
|
c->buffer[labeljt] |= (uint32_t)(labelwt - labeljt) << 8;
|
||||||
|
|
||||||
/* Pop scope and return nil slot */
|
/* Pop scope and return nil slot */
|
||||||
janetc_popscope(c);
|
janetc_popscope(c);
|
||||||
|
@ -133,7 +133,6 @@ extern "C" {
|
|||||||
#define JANET_TYPED_ARRAY
|
#define JANET_TYPED_ARRAY
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* How to export symbols */
|
/* How to export symbols */
|
||||||
#ifndef JANET_API
|
#ifndef JANET_API
|
||||||
#ifdef JANET_WINDOWS
|
#ifdef JANET_WINDOWS
|
||||||
|
Loading…
x
Reference in New Issue
Block a user