From 07829b90d74c582d5e5c477ae140a71111779e9c Mon Sep 17 00:00:00 2001 From: Wenyong Huang Date: Thu, 5 May 2022 12:43:00 +0800 Subject: [PATCH] Fix allocate zero size memory warning (#1143) Fix allocate zero size memory warning reported by wasm_runtime_malloc when allocating the import fun pointers if the import func count is 0: `warning: wasm_runtime_malloc with size zero` --- core/iwasm/interpreter/wasm_runtime.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/iwasm/interpreter/wasm_runtime.c b/core/iwasm/interpreter/wasm_runtime.c index 69ba8d71c..dc68fcc52 100644 --- a/core/iwasm/interpreter/wasm_runtime.c +++ b/core/iwasm/interpreter/wasm_runtime.c @@ -581,8 +581,9 @@ functions_instantiate(const WASMModule *module, WASMModuleInstance *module_inst, } total_size = sizeof(void *) * (uint64)module->import_function_count; - if (!(module_inst->import_func_ptrs = - runtime_malloc(total_size, error_buf, error_buf_size))) { + if (total_size > 0 + && !(module_inst->import_func_ptrs = + runtime_malloc(total_size, error_buf, error_buf_size))) { wasm_runtime_free(functions); return NULL; }