fix(c-api) Ensure that uninitialized boxed vec are zeroed.

This patch updates how `wasm_$name_vec_new_uninitialized` creates the
vector. The vector is now fully allocated with `null` pointer for each
item, instead of having an empty vector with the initial capacity set
to `length`. That way, we are sure the vector is zeroed correctly.
This commit is contained in:
Ivan Enderlin
2020-12-18 11:47:04 +01:00
parent 40fa9c08c7
commit 2ca30fe634

View File

@@ -326,7 +326,7 @@ int main() {
```"]
#[no_mangle]
pub unsafe extern "C" fn [<wasm_ $name _vec_new_uninitialized>](out: *mut [<wasm_ $name _vec_t>], length: usize) {
let mut bytes: Vec<*mut [<wasm_ $name _t>]> = Vec::with_capacity(length);
let mut bytes: Vec<*mut [<wasm_ $name _t>]> = vec![::std::ptr::null_mut(); length];
let pointer = bytes.as_mut_ptr();
(*out).data = pointer;