Skip to content

Commit 45416cd

Browse files
committed
add comment about maintaining OsStr encoding
1 parent e4a65e8 commit 45416cd

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

src/libstd/ffi/os_str.rs

+2
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,8 @@ impl OsStr {
534534
fn from_inner_mut(inner: &mut Slice) -> &mut OsStr {
535535
// Safety: OsStr is just a wrapper of Slice,
536536
// therefore converting &mut Slice to &mut OsStr is safe.
537+
// Any method that mutates OsStr must be careful not to
538+
// break platform-specific encoding, in particular Wtf8 on Windows.
537539
unsafe { &mut *(inner as *mut Slice as *mut OsStr) }
538540
}
539541

src/libstd/sys/windows/os_str.rs

+2
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ impl Buf {
8787
// Safety: Slice is just a wrapper for Wtf8,
8888
// and self.inner.as_mut_slice() returns &mut Wtf8.
8989
// Therefore, transmuting &mut Wtf8 to &mut Slice is safe.
90+
// Additionally, care should be taken to ensure the slice
91+
// is always valid Wtf8.
9092
unsafe { mem::transmute(self.inner.as_mut_slice()) }
9193
}
9294

0 commit comments

Comments
 (0)