From c6dc1328a3b8e462caeceb84bcd9f7a881d2a61b Mon Sep 17 00:00:00 2001 From: Laine Taffin Altman Date: Fri, 8 Mar 2024 07:31:21 -0800 Subject: [PATCH] UB fix: remove impl Zeroable for Infallible It is not enough for a type to be a ZST to guarantee that zeroed memory is a valid value for it; it must also be inhabited. Creating a value of an uninhabited type, ZST or no, is immediate UB. --- src/lib.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c80e2ba..4e4b7f1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1485,8 +1485,9 @@ impl_zeroable! { i8, i16, i32, i64, i128, isize, f32, f64, - // SAFETY: These are ZSTs, there is nothing to zero. - {} PhantomData, core::marker::PhantomPinned, Infallible, (), + // SAFETY: These are inhabited ZSTs, there is nothing to zero + // and a valid value exists. + {} PhantomData, core::marker::PhantomPinned, (), // SAFETY: Type is allowed to take any value, including all zeros. {} MaybeUninit,