Skip to content

Commit

Permalink
Set length of vector *after* actually having written to it
Browse files Browse the repository at this point in the history
  • Loading branch information
marmeladema authored and dwrensha committed Aug 31, 2022
1 parent 62d6a90 commit 471626e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion capnp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 471626e

Please sign in to comment.