From d8c696f095054f45f88fbaf17e5fcbde1f4037d3 Mon Sep 17 00:00:00 2001 From: Volodymyr Shymanskyy Date: Thu, 26 Dec 2019 02:02:26 +0200 Subject: [PATCH] Cleanup --- platforms/app/main.c | 8 +++++++- source/m3_api_wasi.c | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/platforms/app/main.c b/platforms/app/main.c index 7558721..8aa2e12 100644 --- a/platforms/app/main.c +++ b/platforms/app/main.c @@ -24,11 +24,17 @@ M3Result repl_load (IM3Runtime runtime, const char* fn) fsize = ftell(f); fseek (f, 0, SEEK_SET); - if (fsize > 10*1024*1024) { + if (fsize < 8) { + return "file is too small"; + } else if (fsize > 10*1024*1024) { return "file too big"; } wasm = (u8*) malloc(fsize); + if (!wasm) { + return "cannot allocate memory for wasm binary"; + } + fread (wasm, 1, fsize, f); fclose (f); diff --git a/source/m3_api_wasi.c b/source/m3_api_wasi.c index 43a051b..6e7dd0c 100644 --- a/source/m3_api_wasi.c +++ b/source/m3_api_wasi.c @@ -360,7 +360,7 @@ m3ApiRawFunction(m3_wasi_unstable_path_open) memcpy (host_path, path, path_len); host_path [path_len] = '\0'; // NULL terminator - printf ("== path_open: %s\n", host_path); + //printf ("== path_open: %s\n", host_path); #ifdef _WIN32 // TODO: This all needs a proper implementation