diff --git a/src/core/array.c b/src/core/array.c index 336d0c44..8cccbd44 100644 --- a/src/core/array.c +++ b/src/core/array.c @@ -165,7 +165,8 @@ static Janet cfun_array_slice(int32_t argc, Janet *argv) { JanetRange range = janet_getslice(argc, argv); JanetView view = janet_getindexed(argv, 0); JanetArray *array = janet_array(range.end - range.start); - memcpy(array->data, view.items + range.start, sizeof(Janet) * (range.end - range.start)); + if (array->data) + memcpy(array->data, view.items + range.start, sizeof(Janet) * (range.end - range.start)); array->count = range.end - range.start; return janet_wrap_array(array); } diff --git a/src/core/asm.c b/src/core/asm.c index 02eb0f96..fc9b5555 100644 --- a/src/core/asm.c +++ b/src/core/asm.c @@ -642,7 +642,7 @@ static JanetAssembleResult janet_asm1(JanetAssembler *parent, Janet source, int } /* Allocate bytecode array */ def->bytecode_length = blength; - def->bytecode = malloc(sizeof(int32_t) * blength); + def->bytecode = malloc(sizeof(uint32_t) * blength); if (NULL == def->bytecode) { JANET_OUT_OF_MEMORY; } diff --git a/src/core/buffer.c b/src/core/buffer.c index 1809f512..ddecc67a 100644 --- a/src/core/buffer.c +++ b/src/core/buffer.c @@ -172,7 +172,8 @@ static Janet cfun_buffer_new_filled(int32_t argc, Janet *argv) { byte = janet_getinteger(argv, 1) & 0xFF; } JanetBuffer *buffer = janet_buffer(count); - memset(buffer->data, byte, count); + if (buffer->data) + memset(buffer->data, byte, count); buffer->count = count; return janet_wrap_buffer(buffer); } @@ -236,7 +237,8 @@ static Janet cfun_buffer_slice(int32_t argc, Janet *argv) { JanetRange range = janet_getslice(argc, argv); JanetByteView view = janet_getbytes(argv, 0); JanetBuffer *buffer = janet_buffer(range.end - range.start); - memcpy(buffer->data, view.bytes + range.start, range.end - range.start); + if (buffer->data) + memcpy(buffer->data, view.bytes + range.start, range.end - range.start); buffer->count = range.end - range.start; return janet_wrap_buffer(buffer); } diff --git a/src/core/debug.c b/src/core/debug.c index 033fb3e7..80603943 100644 --- a/src/core/debug.c +++ b/src/core/debug.c @@ -192,7 +192,7 @@ static Janet cfun_debug_break(int32_t argc, Janet *argv) { static Janet cfun_debug_unbreak(int32_t argc, Janet *argv) { JanetFuncDef *def; - int32_t offset; + int32_t offset = 0; helper_find(argc, argv, &def, &offset); janet_debug_unbreak(def, offset); return janet_wrap_nil(); @@ -200,7 +200,7 @@ static Janet cfun_debug_unbreak(int32_t argc, Janet *argv) { static Janet cfun_debug_fbreak(int32_t argc, Janet *argv) { JanetFuncDef *def; - int32_t offset; + int32_t offset = 0; helper_find_fun(argc, argv, &def, &offset); janet_debug_break(def, offset); return janet_wrap_nil(); diff --git a/src/core/gc.c b/src/core/gc.c index 3d16d16e..88bb538b 100644 --- a/src/core/gc.c +++ b/src/core/gc.c @@ -391,9 +391,8 @@ static int janet_gc_idequals(Janet lhs, Janet rhs) { * a value and all its children. */ int janet_gcunroot(Janet root) { Janet *vtop = janet_vm_roots + janet_vm_root_count; - Janet *v = janet_vm_roots; /* Search from top to bottom as access is most likely LIFO */ - for (v = janet_vm_roots; v < vtop; v++) { + for (Janet *v = janet_vm_roots; v < vtop; v++) { if (janet_gc_idequals(root, *v)) { *v = janet_vm_roots[--janet_vm_root_count]; return 1; @@ -405,10 +404,9 @@ int janet_gcunroot(Janet root) { /* Remove a root value from the GC. This sets the effective reference count to 0. */ int janet_gcunrootall(Janet root) { Janet *vtop = janet_vm_roots + janet_vm_root_count; - Janet *v = janet_vm_roots; int ret = 0; /* Search from top to bottom as access is most likely LIFO */ - for (v = janet_vm_roots; v < vtop; v++) { + for (Janet *v = janet_vm_roots; v < vtop; v++) { if (janet_gc_idequals(root, *v)) { *v = janet_vm_roots[--janet_vm_root_count]; vtop--; diff --git a/src/core/os.c b/src/core/os.c index 2e6b0150..f7e50c01 100644 --- a/src/core/os.c +++ b/src/core/os.c @@ -125,6 +125,7 @@ static Janet os_execute(int32_t argc, Janet *argv) { static Janet os_execute(int32_t argc, Janet *argv) { janet_arity(argc, 1, -1); const uint8_t **child_argv = malloc(sizeof(uint8_t *) * (argc + 1)); + int status = 0; if (NULL == child_argv) { JANET_OUT_OF_MEMORY; } @@ -141,9 +142,10 @@ static Janet os_execute(int32_t argc, Janet *argv) { if (-1 == execve((const char *)child_argv[0], (char **)child_argv, NULL)) { exit(1); } + } else { + waitpid(pid, &status, 0); } - int status; - waitpid(pid, &status, 0); + free(child_argv); return janet_wrap_integer(status); } #endif diff --git a/src/core/peg.c b/src/core/peg.c index 61a86755..23611364 100644 --- a/src/core/peg.c +++ b/src/core/peg.c @@ -946,9 +946,11 @@ static uint32_t peg_compile1(Builder *b, Janet peg) { sizeof(peg_specials) / sizeof(SpecialPair), sizeof(SpecialPair), sym); - if (!sp) + if (sp) { + sp->special(b, len - 1, tup + 1); + } else { peg_panicf(b, "unknown special %S", sym); - sp->special(b, len - 1, tup + 1); + } break; } } diff --git a/src/core/string.c b/src/core/string.c index c2db76a4..94df1417 100644 --- a/src/core/string.c +++ b/src/core/string.c @@ -182,8 +182,7 @@ static Janet cfun_string_repeat(int32_t argc, Janet *argv) { if (mulres > INT32_MAX) janet_panic("result string is too long"); uint8_t *newbuf = janet_string_begin((int32_t) mulres); uint8_t *end = newbuf + mulres; - uint8_t *p = newbuf; - for (p = newbuf; p < end; p += view.len) { + for (uint8_t *p = newbuf; p < end; p += view.len) { memcpy(p, view.bytes, view.len); } return janet_wrap_string(janet_string_end(newbuf)); diff --git a/src/core/symcache.c b/src/core/symcache.c index f045a3b6..dff65617 100644 --- a/src/core/symcache.c +++ b/src/core/symcache.c @@ -44,7 +44,7 @@ JANET_THREAD_LOCAL uint32_t janet_vm_cache_deleted = 0; /* Initialize the cache (allocate cache memory) */ void janet_symcache_init() { janet_vm_cache_capacity = 1024; - janet_vm_cache = calloc(1, janet_vm_cache_capacity * sizeof(const uint8_t **)); + janet_vm_cache = calloc(1, janet_vm_cache_capacity * sizeof(const uint8_t *)); if (NULL == janet_vm_cache) { JANET_OUT_OF_MEMORY; } @@ -121,7 +121,7 @@ notfound: static void janet_cache_resize(uint32_t newCapacity) { uint32_t i, oldCapacity; const uint8_t **oldCache = janet_vm_cache; - const uint8_t **newCache = calloc(1, newCapacity * sizeof(const uint8_t **)); + const uint8_t **newCache = calloc(1, newCapacity * sizeof(const uint8_t *)); if (newCache == NULL) { JANET_OUT_OF_MEMORY; }