# HG changeset patch # User Paul Fisher # Date 1751749893 14400 # Node ID add7228adb2f198a73e4ebb4df3bdac288a9e50b # Parent 33b9622ed6d246df1751f48c5a01827ed89aaeff Neaten up some stuff in libpam-sys memory module. diff -r 33b9622ed6d2 -r add7228adb2f libpam-sys/libpam-sys-helpers/src/memory.rs --- a/libpam-sys/libpam-sys-helpers/src/memory.rs Thu Jul 03 23:57:49 2025 -0400 +++ b/libpam-sys/libpam-sys-helpers/src/memory.rs Sat Jul 05 17:11:33 2025 -0400 @@ -199,7 +199,7 @@ } fn assert_size() { - debug_assert_eq!( + assert_eq!( mem::size_of::(), mem::size_of::(), "type {t} is not the size of {that}", @@ -239,6 +239,7 @@ /// /// For an implementation example, see the implementation of this trait /// for [`Vec`]. +#[allow(clippy::wrong_self_convention)] pub trait Buffer { /// Allocates a buffer of `len` elements, filled with the default. fn allocate(len: usize) -> Self; @@ -305,7 +306,7 @@ /// extension from Linux-PAM. pub struct BinaryPayload { /// The total byte size of the message, including this header, - /// as a u32 in network byte order (big endian). + /// as u32 in network byte order (big endian). pub total_bytes_u32be: [u8; 4], /// A tag used to provide some kind of hint as to what the data is. /// Its meaning is undefined. @@ -514,7 +515,6 @@ } #[allow(deprecated)] - #[cfg(debug_assertions)] #[test] #[should_panic] fn test_iter_xsso_wrong_size() { @@ -524,7 +524,6 @@ } #[allow(deprecated)] - #[cfg(debug_assertions)] #[test] #[should_panic] fn test_iter_linux_wrong_size() { @@ -556,13 +555,26 @@ #[allow(deprecated)] #[test] fn test_iter_ptr_ptr() { - let strs = vec![Box::new("a"), Box::new("b"), Box::new("c"), Box::new("D")]; - let ptr: *const *const &str = strs.as_ptr().cast(); + // These boxes are larger than a single pointer because we want to + // make sure they're not accidentally allocated adjacently + // in such a way that it's compatible with X/SSO. + // + // a pointer to (&str, i32) can be treated as a pointer to (&str). + #[repr(C)] + struct pair(&'static str, i32); + let boxes = vec![ + Box::new(pair("a", 1)), + Box::new(pair("b", 2)), + Box::new(pair("c", 3)), + Box::new(pair("D", 4)), + ]; + let ptr: *const *const &str = boxes.as_ptr().cast(); let got: Vec<&str> = unsafe { PtrPtrVec::iter_over_linux(ptr, 4) } .cloned() .collect(); assert_eq!(vec!["a", "b", "c", "D"], got); + // On the other hand, we explicitly want these to be adjacent. let nums = [-1i8, 2, 3]; let ptr = nums.as_ptr(); let got: Vec = unsafe { PtrPtrVec::iter_over_xsso(&ptr, 3) }