Set length of vector *after* actually having written to it
@@ -79,9 +79,9 @@ impl Word {
pub fn allocate_zeroed_vec(length: usize) -> Vec<Word> {
let mut result: Vec<Word> = Vec::with_capacity(length);
unsafe {
- result.set_len(length);
let p: *mut u8 = result.as_mut_ptr() as *mut u8;
core::ptr::write_bytes(p, 0u8, length * core::mem::size_of::<Word>());
+ result.set_len(length);
}
result
}
