Skip to content

Commit

Permalink
manually init
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 authored and Licenser committed Jul 27, 2023
1 parent a66d8fb commit 2c43ab7
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ mod known_key;
pub use known_key::{Error as KnownKeyError, KnownKey};

pub use crate::tape::{Node, Tape};
use std::alloc::{alloc_zeroed, handle_alloc_error, Layout};
use std::alloc::{alloc, handle_alloc_error, Layout};
use std::ops::{Deref, DerefMut};
use std::ptr::NonNull;

Expand Down Expand Up @@ -490,6 +490,14 @@ impl<'de> Deserializer<'de> {
// ensure we have a 0 to terminate the buffer
std::ptr::write(input_buffer.as_mut_ptr().add(len), 0);

// initialize all remaingin bytes
if len < input_buffer.capacity() {
for i in len..input_buffer.capacity() {
std::ptr::write(input_buffer.as_mut_ptr().add(i), 0);
}
}

// safety: all bytes are initialized
input_buffer.set_len(input_buffer.capacity());
};

Expand Down Expand Up @@ -710,7 +718,7 @@ impl AlignedBuf {
if mem::size_of::<usize>() < 8 && capacity > isize::MAX as usize {
Self::capacity_overflow()
}
let inner = match unsafe { NonNull::new(alloc_zeroed(layout)) } {
let inner = match unsafe { NonNull::new(alloc(layout)) } {
Some(ptr) => ptr,
None => handle_alloc_error(layout),
};
Expand Down

0 comments on commit 2c43ab7

Please sign in to comment.