Zero the buffer passed from write_with
This commit is contained in:
parent
9a6e8b3807
commit
c8e7c6261e
1 changed files with 9 additions and 2 deletions
|
|
@ -35,8 +35,15 @@ impl MemEncoder {
|
|||
self.data.reserve(N);
|
||||
|
||||
let old_len = self.data.len();
|
||||
// SAFETY: fix
|
||||
let buf = unsafe { &mut *(self.data.as_mut_ptr().add(old_len) as *mut [u8; N]) };
|
||||
|
||||
// SAFETY: The above `reserve` ensures that there is enough
|
||||
// room to write the encoded value to the vector's internal buffer.
|
||||
// The memory is also initialized as 0.
|
||||
let buf = unsafe {
|
||||
let buf = self.data.as_mut_ptr().add(old_len) as *mut [u8; N];
|
||||
*buf = [0; N];
|
||||
&mut *buf
|
||||
};
|
||||
let written = visitor(buf);
|
||||
if written > N {
|
||||
Self::panic_invalid_write::<N>(written);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue