diff --git a/crates/wasmedge-sys/src/async/function.rs b/crates/wasmedge-sys/src/async/function.rs index ac7095610..f3c84aa3d 100644 --- a/crates/wasmedge-sys/src/async/function.rs +++ b/crates/wasmedge-sys/src/async/function.rs @@ -37,14 +37,21 @@ unsafe extern "C" fn wrap_async_fn( let data = &mut *(data as *mut Data); // arguments - let input = { + let input = if params.is_null() || param_len == 0 { + vec![] + } else { let raw_input = unsafe { std::slice::from_raw_parts(params, param_len as usize) }; raw_input.iter().map(|r| (*r).into()).collect::>() }; // returns let return_len = return_len as usize; - let raw_returns = unsafe { std::slice::from_raw_parts_mut(returns, return_len) }; + let mut empty_return = []; + let raw_returns = if returns.is_null() || return_len == 0 { + &mut empty_return + } else { + unsafe { std::slice::from_raw_parts_mut(returns, return_len) } + }; // get and call host function let real_fn: AsyncFn<'_, '_, '_, '_, Data> = std::mem::transmute(key_ptr);