Skip to content

Commit

Permalink
single memset
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 authored and Licenser committed Jul 27, 2023
1 parent f80656b commit cb53426
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,14 +487,10 @@ impl<'de> Deserializer<'de> {
unsafe {
std::ptr::copy_nonoverlapping(input.as_ptr(), input_buffer.as_mut_ptr(), len);

// ensure we have a 0 to terminate the buffer
std::ptr::write(input_buffer.as_mut_ptr().add(len), 0);

// initialize all remaining bytes
if len < input_buffer.capacity() {
for i in len..input_buffer.capacity() {
std::ptr::write(input_buffer.as_mut_ptr().add(i), 0);
}
// this also ensures we have a 0 to terminate the buffer
for i in len..input_buffer.capacity() {
std::ptr::write(input_buffer.as_mut_ptr().add(i), 0);
}

// safety: all bytes are initialized
Expand Down

0 comments on commit cb53426

Please sign in to comment.