diff --git a/core/iwasm/interpreter/wasm_loader.c b/core/iwasm/interpreter/wasm_loader.c index f1da1b11d..ccd7fbdb1 100644 --- a/core/iwasm/interpreter/wasm_loader.c +++ b/core/iwasm/interpreter/wasm_loader.c @@ -1691,8 +1691,14 @@ init_function_local_offsets(WASMFunction *func, uint32 i, local_offset = 0; uint64 total_size = sizeof(uint16) * ((uint64)param_count + local_count); - if (!(func->local_offsets = - loader_malloc(total_size, error_buf, error_buf_size))) { + /* + * Only allocate memory when total_size is not 0, + * or the return value of malloc(0) might be NULL on some platforms, + * which causes wasm loader return false. + */ + if (total_size > 0 + && !(func->local_offsets = + loader_malloc(total_size, error_buf, error_buf_size))) { return false; } diff --git a/core/iwasm/interpreter/wasm_mini_loader.c b/core/iwasm/interpreter/wasm_mini_loader.c index 0d83c2dcd..030d93833 100644 --- a/core/iwasm/interpreter/wasm_mini_loader.c +++ b/core/iwasm/interpreter/wasm_mini_loader.c @@ -853,8 +853,9 @@ init_function_local_offsets(WASMFunction *func, uint32 i, local_offset = 0; uint64 total_size = sizeof(uint16) * ((uint64)param_count + local_count); - if (!(func->local_offsets = - loader_malloc(total_size, error_buf, error_buf_size))) { + if (total_size > 0 + && !(func->local_offsets = + loader_malloc(total_size, error_buf, error_buf_size))) { return false; }