Mercurial > crates > nonstick
diff libpam-sys/libpam-sys-helpers/src/memory.rs @ 143:ebb71a412b58
Turn everything into OsString and Just Walk Out! for strings with nul.
To reduce the hazard surface of the API, this replaces most uses of &str
with &OsStr (and likewise with String/OsString).
Also, I've decided that instead of dealing with callers putting `\0`
in their parameters, I'm going to follow the example of std::env and
Just Walk Out! (i.e., panic!()).
This makes things a lot less annoying for both me and (hopefully) users.
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Sat, 05 Jul 2025 22:12:46 -0400 |
parents | add7228adb2f |
children |
line wrap: on
line diff
--- a/libpam-sys/libpam-sys-helpers/src/memory.rs Sat Jul 05 21:49:27 2025 -0400 +++ b/libpam-sys/libpam-sys-helpers/src/memory.rs Sat Jul 05 22:12:46 2025 -0400 @@ -371,11 +371,11 @@ let header: &Self = ptr.as_ref().unwrap_unchecked(); (&Self::buffer_of(ptr)[5..], header.data_type) } - + /// Zeroes out the data of this payload. - /// + /// /// # Safety - /// + /// /// - The pointer must point to a valid `BinaryPayload`. /// - The binary payload must not be used in the future, /// since its length metadata is gone and so its buffer is unknown. @@ -455,7 +455,10 @@ /// allocated by) [`Self::new`]. For instance, passing a pointer allocated /// by `malloc` to `OwnedBinaryPayload::<Vec<u8>>::from_ptr` is not allowed. pub unsafe fn from_ptr(ptr: NonNull<BinaryPayload>) -> Self { - Self(O::from_ptr(ptr.cast(), BinaryPayload::total_bytes(ptr.as_ptr()))) + Self(O::from_ptr( + ptr.cast(), + BinaryPayload::total_bytes(ptr.as_ptr()), + )) } }