Skip to content

File tree

1 file changed

+6
-13
lines changed
  • library/std/src/sys/pal/sgx/abi/usercalls

1 file changed

+6
-13
lines changed
 

‎library/std/src/sys/pal/sgx/abi/usercalls/alloc.rs

+6-13
Original file line numberDiff line numberDiff line change
@@ -678,25 +678,18 @@ where
678678
unsafe { (*self.0.get()).len() }
679679
}
680680

681-
/// Copies the value from user memory and place it into `dest`. Afterwards,
682-
/// `dest` will contain exactly `self.len()` elements.
683-
///
684-
/// # Panics
685-
/// This function panics if the destination doesn't have the same size as
686-
/// the source. This can happen for dynamically-sized types such as slices.
687-
pub fn copy_to_enclave_vec(&self, dest: &mut Vec<T>) {
688-
if let Some(missing) = self.len().checked_sub(dest.capacity()) {
689-
dest.reserve(missing)
690-
}
681+
/// Copies the value from user memory and appends it to `dest`.
682+
pub fn append_to_enclave_vec(&self, dest: &mut Vec<T>) {
683+
dest.reserve(self.len());
684+
self.copy_to_enclave(&mut dest.spare_capacity_mut()[..self.len()]);
691685
// SAFETY: We reserve enough space above.
692-
unsafe { dest.set_len(self.len()) };
693-
self.copy_to_enclave(&mut dest[..]);
686+
unsafe { dest.set_len(dest.len() + self.len()) };
694687
}
695688

696689
/// Copies the value from user memory into a vector in enclave memory.
697690
pub fn to_enclave(&self) -> Vec<T> {
698691
let mut ret = Vec::with_capacity(self.len());
699-
self.copy_to_enclave_vec(&mut ret);
692+
self.append_to_enclave_vec(&mut ret);
700693
ret
701694
}
702695

0 commit comments

Comments
 (0)
Please sign in to comment.