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

This commit is contained in:
Ivan Enderlin
2020-02-10 11:31:54 +01:00
parent b1a0e1933c
commit ee0f05f9a1

View File

@ -198,10 +198,15 @@ pub extern "C" fn wasmer_memory_data(memory: *const wasmer_memory_t) -> *mut u8
/// ```
#[allow(clippy::cast_ptr_alignment)]
#[no_mangle]
pub extern "C" fn wasmer_memory_data_length(mem: *mut wasmer_memory_t) -> u32 {
let memory = mem as *mut Memory;
let Bytes(len) = unsafe { (*memory).size().bytes() };
len as u32
pub extern "C" fn wasmer_memory_data_length(memory: *mut wasmer_memory_t) -> u32 {
if memory.is_null() {
return 0;
}
let memory = unsafe { &*(memory as *const Memory) };
let Bytes(length) = memory.size().bytes();
length as u32
}
/// Frees memory for the given Memory