Skip to content

Commit 471626e

Browse files
marmelademadwrensha
authored andcommitted
Set length of vector *after* actually having written to it
1 parent 62d6a90 commit 471626e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

capnp/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ impl Word {
7979
pub fn allocate_zeroed_vec(length: usize) -> Vec<Word> {
8080
let mut result: Vec<Word> = Vec::with_capacity(length);
8181
unsafe {
82-
result.set_len(length);
8382
let p: *mut u8 = result.as_mut_ptr() as *mut u8;
8483
core::ptr::write_bytes(p, 0u8, length * core::mem::size_of::<Word>());
84+
result.set_len(length);
8585
}
8686
result
8787
}

0 commit comments

Comments
 (0)