Safer CryptoBufferBuilder::build
This commit is contained in:
parent
5957ce94cc
commit
75ef523230
|
|
@ -16,7 +16,7 @@ use foreign_types::ForeignType;
|
|||
use foreign_types::ForeignTypeRef;
|
||||
use libc::{c_char, c_int, c_uchar, c_uint, c_void};
|
||||
use std::ffi::CStr;
|
||||
use std::mem::MaybeUninit;
|
||||
use std::mem::{self, MaybeUninit};
|
||||
use std::ptr;
|
||||
use std::slice;
|
||||
use std::str;
|
||||
|
|
@ -769,12 +769,8 @@ impl<'a> CryptoBufferBuilder<'a> {
|
|||
// Make sure all bytes in buffer initialized as required by Boring SSL.
|
||||
return Err(ErrorStack::internal_error_str("invalid len"));
|
||||
}
|
||||
unsafe {
|
||||
let mut result = ptr::null_mut();
|
||||
ptr::swap(&mut self.buffer, &mut result);
|
||||
std::mem::forget(self);
|
||||
Ok(result)
|
||||
}
|
||||
// Drop is no-op if the buffer is null
|
||||
Ok(mem::replace(&mut self.buffer, ptr::null_mut()))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue