feat(runtime-c-api) wasmer_memory_length returns 0 if memory is NULL.

This commit is contained in:
Ivan Enderlin
2020-02-10 11:04:41 +01:00
parent 78056df6cc
commit 534db599b2

View File

@@ -134,9 +134,14 @@ pub extern "C" fn wasmer_memory_grow(memory: *mut wasmer_memory_t, delta: u32) -
#[allow(clippy::cast_ptr_alignment)]
#[no_mangle]
pub extern "C" fn wasmer_memory_length(memory: *const wasmer_memory_t) -> u32 {
if memory.is_null() {
return 0;
}
let memory = unsafe { &*(memory as *const Memory) };
let Pages(len) = memory.size();
len
let Pages(length) = memory.size();
length
}
/// Gets the start pointer to the bytes within a Memory