Skip to content

Commit

Permalink
fix: don't let ptr::copy copy from null ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
KristianMika committed May 21, 2024
1 parent 479ab31 commit 6bad25e
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/cryptoki/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ pub unsafe trait FromPointer<T> {

unsafe impl<T> FromPointer<T> for Vec<T> {
unsafe fn from_pointer(pointer: *mut T, count: usize) -> Self {
if pointer.is_null() {
return Vec::new();
}
let mut vector = Vec::with_capacity(count);
unsafe {
ptr::copy(pointer, vector.as_mut_ptr(), count);
Expand Down

0 comments on commit 6bad25e

Please sign in to comment.