1
0
mirror of https://github.com/janet-lang/janet synced 2025-10-31 07:33:01 +00:00

Try to remove potential overflow bugs.

Also make integer to size_t casts explicit rather than relying on
int32_t * sizeof(x) = size_t. This is kind of a personal preference for
this problem.
This commit is contained in:
Calvin Rose
2020-01-02 22:02:57 -06:00
parent a1cd759759
commit 6c7f376410
23 changed files with 82 additions and 72 deletions

View File

@@ -32,7 +32,7 @@
static void *janet_memalloc_empty_local(int32_t count) {
int32_t i;
void *mem = janet_smalloc(count * sizeof(JanetKV));
void *mem = janet_smalloc((size_t) count * sizeof(JanetKV));
JanetKV *mmem = (JanetKV *)mem;
for (i = 0; i < count; i++) {
JanetKV *kv = mmem + i;
@@ -241,7 +241,7 @@ JanetTable *janet_table_clone(JanetTable *table) {
if (NULL == newTable->data) {
JANET_OUT_OF_MEMORY;
}
memcpy(newTable->data, table->data, table->capacity * sizeof(JanetKV));
memcpy(newTable->data, table->data, (size_t) table->capacity * sizeof(JanetKV));
return newTable;
}