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