From df2b93ea8183a0a087c9b0d59b82ba8ff3142e77 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 20 Jan 2020 15:52:14 +0100 Subject: [PATCH] fix(runtime-c-api) `wasmer_instance_context_data_get` returns `void` if `instance` is null. --- lib/runtime-c-api/src/instance.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/runtime-c-api/src/instance.rs b/lib/runtime-c-api/src/instance.rs index a3b587957..4dea693bc 100644 --- a/lib/runtime-c-api/src/instance.rs +++ b/lib/runtime-c-api/src/instance.rs @@ -469,13 +469,25 @@ pub extern "C" fn wasmer_instance_context_memory( memory as *const Memory as *const wasmer_memory_t } -/// Gets the `data` field within the context. +/// Gets the data that can be hold by an instance. +/// +/// This function is complementary of +/// `wasmer_instance_context_data_set()`. Please read its +/// documentation. You can also read the documentation of +/// `wasmer_instance_context_t` to get other examples. +/// +/// This function returns nothing if `ctx` is a null pointer. #[allow(clippy::cast_ptr_alignment)] #[no_mangle] pub extern "C" fn wasmer_instance_context_data_get( ctx: *const wasmer_instance_context_t, ) -> *mut c_void { + if ctx.is_null() { + return ptr::null_mut() as _; + } + let ctx = unsafe { &*(ctx as *const Ctx) }; + ctx.data }