Skip to content

Commit e65001f

Browse files
authored
clippy: Add missing unsafe function documentation (#412)
* clippy: fix unsafce function docs missing from clippy Signed-off-by: Jerens Lensun <[email protected]> * clippy: fix clippy warning identity_op on redundant casting Signed-off-by: Jerens Lensun <[email protected]> --------- Signed-off-by: Jerens Lensun <[email protected]>
1 parent 0be20e3 commit e65001f

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/platform/macos/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,11 @@ impl Deref for OsIpcSharedMemory {
901901
}
902902

903903
impl OsIpcSharedMemory {
904+
/// # Safety
905+
///
906+
/// This is safe if there is only one reader/writer on the data.
907+
/// User can achieve this by not cloning [`IpcSharedMemory`]
908+
/// and serializing/deserializing only once.
904909
#[inline]
905910
pub unsafe fn deref_mut(&mut self) -> &mut [u8] {
906911
if self.ptr.is_null() && self.length > 0 {

src/platform/windows/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,6 +1829,11 @@ impl Deref for OsIpcSharedMemory {
18291829
}
18301830

18311831
impl OsIpcSharedMemory {
1832+
/// # Safety
1833+
///
1834+
/// This is safe if there is only one reader/writer on the data.
1835+
/// User can achieve this by not cloning [`IpcSharedMemory`]
1836+
/// and serializing/deserializing only once.
18321837
#[inline]
18331838
pub unsafe fn deref_mut(&mut self) -> &mut [u8] {
18341839
assert!(!self.view_handle.Value.is_null() && self.handle.is_valid());
@@ -1840,10 +1845,7 @@ impl OsIpcSharedMemory {
18401845
fn new(length: usize) -> Result<OsIpcSharedMemory, WinError> {
18411846
unsafe {
18421847
assert!(length < u32::MAX as usize);
1843-
let (lhigh, llow) = (
1844-
length.checked_shr(32).unwrap_or(0) as u32,
1845-
(length & 0xffffffff) as u32,
1846-
);
1848+
let (lhigh, llow) = (length.checked_shr(32).unwrap_or(0) as u32, length as u32);
18471849
let handle = CreateFileMappingA(
18481850
INVALID_HANDLE_VALUE,
18491851
None,

0 commit comments

Comments
 (0)