Skip to content

Commit b4aa64d

Browse files
committed
sockopt's Set and Get traits are not unsafe
They were properly marked as unsafe as originally written. However, when the internal mem::zeroed() was replaced by mem::uninitialized(), these traits actually became safe. Only Get::assume_init() is actually unsafe. Fixes a warning with the latest Clippy.
1 parent c7a8193 commit b4aa64d

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

src/sys/socket/sockopt.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -611,9 +611,9 @@ impl<T> SetSockOpt for AlgSetKey<T> where T: AsRef<[u8]> + Clone {
611611
*/
612612

613613
/// Helper trait that describes what is expected from a `GetSockOpt` getter.
614-
unsafe trait Get<T> {
614+
trait Get<T> {
615615
/// Returns an uninitialized value.
616-
unsafe fn uninit() -> Self;
616+
fn uninit() -> Self;
617617
/// Returns a pointer to the stored value. This pointer will be passed to the system's
618618
/// `getsockopt` call (`man 3p getsockopt`, argument `option_value`).
619619
fn ffi_ptr(&mut self) -> *mut c_void;
@@ -625,7 +625,7 @@ unsafe trait Get<T> {
625625
}
626626

627627
/// Helper trait that describes what is expected from a `SetSockOpt` setter.
628-
unsafe trait Set<'a, T> {
628+
trait Set<'a, T> {
629629
/// Initialize the setter with a given value.
630630
fn new(val: &'a T) -> Self;
631631
/// Returns a pointer to the stored value. This pointer will be passed to the system's
@@ -642,8 +642,8 @@ struct GetStruct<T> {
642642
val: MaybeUninit<T>,
643643
}
644644

645-
unsafe impl<T> Get<T> for GetStruct<T> {
646-
unsafe fn uninit() -> Self {
645+
impl<T> Get<T> for GetStruct<T> {
646+
fn uninit() -> Self {
647647
GetStruct {
648648
len: mem::size_of::<T>() as socklen_t,
649649
val: MaybeUninit::uninit(),
@@ -669,7 +669,7 @@ struct SetStruct<'a, T: 'static> {
669669
ptr: &'a T,
670670
}
671671

672-
unsafe impl<'a, T> Set<'a, T> for SetStruct<'a, T> {
672+
impl<'a, T> Set<'a, T> for SetStruct<'a, T> {
673673
fn new(ptr: &'a T) -> SetStruct<'a, T> {
674674
SetStruct { ptr }
675675
}
@@ -689,8 +689,8 @@ struct GetBool {
689689
val: MaybeUninit<c_int>,
690690
}
691691

692-
unsafe impl Get<bool> for GetBool {
693-
unsafe fn uninit() -> Self {
692+
impl Get<bool> for GetBool {
693+
fn uninit() -> Self {
694694
GetBool {
695695
len: mem::size_of::<c_int>() as socklen_t,
696696
val: MaybeUninit::uninit(),
@@ -716,7 +716,7 @@ struct SetBool {
716716
val: c_int,
717717
}
718718

719-
unsafe impl<'a> Set<'a, bool> for SetBool {
719+
impl<'a> Set<'a, bool> for SetBool {
720720
fn new(val: &'a bool) -> SetBool {
721721
SetBool { val: if *val { 1 } else { 0 } }
722722
}
@@ -736,8 +736,8 @@ struct GetU8 {
736736
val: MaybeUninit<u8>,
737737
}
738738

739-
unsafe impl Get<u8> for GetU8 {
740-
unsafe fn uninit() -> Self {
739+
impl Get<u8> for GetU8 {
740+
fn uninit() -> Self {
741741
GetU8 {
742742
len: mem::size_of::<u8>() as socklen_t,
743743
val: MaybeUninit::uninit(),
@@ -763,7 +763,7 @@ struct SetU8 {
763763
val: u8,
764764
}
765765

766-
unsafe impl<'a> Set<'a, u8> for SetU8 {
766+
impl<'a> Set<'a, u8> for SetU8 {
767767
fn new(val: &'a u8) -> SetU8 {
768768
SetU8 { val: *val as u8 }
769769
}
@@ -783,8 +783,8 @@ struct GetUsize {
783783
val: MaybeUninit<c_int>,
784784
}
785785

786-
unsafe impl Get<usize> for GetUsize {
787-
unsafe fn uninit() -> Self {
786+
impl Get<usize> for GetUsize {
787+
fn uninit() -> Self {
788788
GetUsize {
789789
len: mem::size_of::<c_int>() as socklen_t,
790790
val: MaybeUninit::uninit(),
@@ -810,7 +810,7 @@ struct SetUsize {
810810
val: c_int,
811811
}
812812

813-
unsafe impl<'a> Set<'a, usize> for SetUsize {
813+
impl<'a> Set<'a, usize> for SetUsize {
814814
fn new(val: &'a usize) -> SetUsize {
815815
SetUsize { val: *val as c_int }
816816
}
@@ -830,8 +830,8 @@ struct GetOsString<T: AsMut<[u8]>> {
830830
val: MaybeUninit<T>,
831831
}
832832

833-
unsafe impl<T: AsMut<[u8]>> Get<OsString> for GetOsString<T> {
834-
unsafe fn uninit() -> Self {
833+
impl<T: AsMut<[u8]>> Get<OsString> for GetOsString<T> {
834+
fn uninit() -> Self {
835835
GetOsString {
836836
len: mem::size_of::<T>() as socklen_t,
837837
val: MaybeUninit::uninit(),
@@ -858,7 +858,7 @@ struct SetOsString<'a> {
858858
val: &'a OsStr,
859859
}
860860

861-
unsafe impl<'a> Set<'a, OsString> for SetOsString<'a> {
861+
impl<'a> Set<'a, OsString> for SetOsString<'a> {
862862
fn new(val: &'a OsString) -> SetOsString {
863863
SetOsString { val: val.as_os_str() }
864864
}

0 commit comments

Comments
 (0)