From 6c967b71f107ba21b60e01c5454ea5b6543cc4f7 Mon Sep 17 00:00:00 2001 From: Xiaokang Qin Date: Wed, 30 Dec 2020 13:37:19 +0800 Subject: [PATCH] Fix two issues for wasm-c-api (#487) Fix incorrect func_type unpacking for results Fix crash for multiple instance usage due to wrong size provided Signed-off-by: Kanghua Yu Signed-off-by: Xiaokang Qin Co-authored-by: Kanghua Yu --- core/iwasm/common/wasm_c_api.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/iwasm/common/wasm_c_api.c b/core/iwasm/common/wasm_c_api.c index c8f7701a..cc1082b9 100644 --- a/core/iwasm/common/wasm_c_api.c +++ b/core/iwasm/common/wasm_c_api.c @@ -523,9 +523,9 @@ wasm_functype_new_internal(WASMType *type_rt) /* WASMType->types[type_rt->param_count : type_rt->result_count) -> func_type->results */ INIT_VEC(func_type->results, wasm_valtype_vec, type_rt->result_count); - for (i = type_rt->param_count; i < type_rt->result_count; ++i) { + for (i = 0; i < type_rt->result_count; ++i) { wasm_valtype_t *result_type = - wasm_valtype_new_internal(*(type_rt->types + i)); + wasm_valtype_new_internal(*(type_rt->types + type_rt->param_count + i)); if (!result_type) { goto failed; } @@ -2603,7 +2603,7 @@ wasm_instance_exports(const wasm_instance_t *instance, wasm_extern_vec_t *out) void wasm_instance_vec_new_uninitialized(wasm_instance_vec_t *out, size_t size) { - generic_vec_init_data((Vector *)out, size, sizeof(wasm_instance_t)); + generic_vec_init_data((Vector *)out, size, sizeof(wasm_instance_t *)); } void