[rust] Add "unsafe" to the testing-mode tor_malloc_ wrapper.

This change lets us remove the allow(unused_unsafe) directive
from allocate_and_copy_string().
This commit is contained in:
Nick Mathewson 2017-10-27 12:49:51 -04:00
parent d64297e4e0
commit 1e66ab363a

View File

@ -12,9 +12,9 @@ extern "C" {
// Defined only for tests, used for testing purposes, so that we don't need // Defined only for tests, used for testing purposes, so that we don't need
// to link to tor C files. Uses the system allocator // to link to tor C files. Uses the system allocator
#[cfg(test)] #[cfg(test)]
extern "C" fn tor_malloc_(size: usize) -> *mut c_void { unsafe extern "C" fn tor_malloc_(size: usize) -> *mut c_void {
use libc::malloc; use libc::malloc;
unsafe { malloc(size) } malloc(size)
} }
/// Allocate memory using tor_malloc_ and copy an existing string into the /// Allocate memory using tor_malloc_ and copy an existing string into the
@ -28,10 +28,6 @@ extern "C" fn tor_malloc_(size: usize) -> *mut c_void {
/// ///
/// A `*mut c_char` that should be freed by tor_free in C /// A `*mut c_char` that should be freed by tor_free in C
/// ///
/// Allow unused unsafe as at compile-time, we get warnings that unsafe is not
/// needed even though this calls tor_malloc in C.
///
#[allow(unused_unsafe)]
pub fn allocate_and_copy_string(src: &String) -> *mut c_char { pub fn allocate_and_copy_string(src: &String) -> *mut c_char {
let bytes: &[u8] = src.as_bytes(); let bytes: &[u8] = src.as_bytes();