diff --git a/src/core/io.c b/src/core/io.c index 7051a90a..4e010615 100644 --- a/src/core/io.c +++ b/src/core/io.c @@ -195,6 +195,9 @@ static Janet cfun_io_fread(int32_t argc, Janet *argv) { } else { fseek(iof->file, 0, SEEK_END); long fsize = ftell(iof->file); + if (fsize < 0) { + janet_panicf("could not get file size of %v", argv[0]); + } fseek(iof->file, 0, SEEK_SET); read_chunk(iof, buffer, (int32_t) fsize); } diff --git a/src/core/wrap.c b/src/core/wrap.c index a1506815..40c37566 100644 --- a/src/core/wrap.c +++ b/src/core/wrap.c @@ -27,6 +27,9 @@ void *janet_memalloc_empty(int32_t count) { int32_t i; void *mem = malloc(count * sizeof(JanetKV)); + if (NULL == mem) { + JANET_OUT_OF_MEMORY; + } JanetKV *mmem = (JanetKV *)mem; for (i = 0; i < count; i++) { JanetKV *kv = mmem + i;