about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTyPR124 <t.ruckinger@gmail.com>2020-03-20 09:00:53 -0400
committerTyPR124 <t.ruckinger@gmail.com>2020-03-20 09:00:53 -0400
commit45416cd91a6bdc493ea62fb3f412713a0fd8e52e (patch)
tree593420101e6b7f0dd0c1e78a471a255c3e82c4c2
parente4a65e83e7ce89ce7a015753a4b8d989416ae2a8 (diff)
downloadrust-45416cd91a6bdc493ea62fb3f412713a0fd8e52e.tar.gz
rust-45416cd91a6bdc493ea62fb3f412713a0fd8e52e.zip
add comment about maintaining OsStr encoding
-rw-r--r--src/libstd/ffi/os_str.rs2
-rw-r--r--src/libstd/sys/windows/os_str.rs2
2 files changed, 4 insertions, 0 deletions
diff --git a/src/libstd/ffi/os_str.rs b/src/libstd/ffi/os_str.rs
index 45417403c10..0fbe8e5dd83 100644
--- a/src/libstd/ffi/os_str.rs
+++ b/src/libstd/ffi/os_str.rs
@@ -534,6 +534,8 @@ impl OsStr {
     fn from_inner_mut(inner: &mut Slice) -> &mut OsStr {
         // Safety: OsStr is just a wrapper of Slice,
         // therefore converting &mut Slice to &mut OsStr is safe.
+        // Any method that mutates OsStr must be careful not to
+        // break platform-specific encoding, in particular Wtf8 on Windows.
         unsafe { &mut *(inner as *mut Slice as *mut OsStr) }
     }
 
diff --git a/src/libstd/sys/windows/os_str.rs b/src/libstd/sys/windows/os_str.rs
index 2820d2b5fe9..ff6885cb274 100644
--- a/src/libstd/sys/windows/os_str.rs
+++ b/src/libstd/sys/windows/os_str.rs
@@ -87,6 +87,8 @@ impl Buf {
         // Safety: Slice is just a wrapper for Wtf8,
         // and self.inner.as_mut_slice() returns &mut Wtf8.
         // Therefore, transmuting &mut Wtf8 to &mut Slice is safe.
+        // Additionally, care should be taken to ensure the slice
+        // is always valid Wtf8.
         unsafe { mem::transmute(self.inner.as_mut_slice()) }
     }