about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJosh Triplett <josh@joshtriplett.org>2022-08-24 15:32:16 +0200
committerJosh Triplett <josh@joshtriplett.org>2022-10-15 00:35:39 +0100
commit6a79da9ab7fbf5d50034751f4c3c185a1144d49b (patch)
tree1b6c5a4876cf8230cdf7de8d3fc719df2b9725a6
parente25fe564d1ea62a1018f603cac39f51dc6f11048 (diff)
downloadrust-6a79da9ab7fbf5d50034751f4c3c185a1144d49b.tar.gz
rust-6a79da9ab7fbf5d50034751f4c3c185a1144d49b.zip
Rewrite FILE_NAME_INFO handling to avoid enlarging slice reference
Rather than referencing a slice's pointer and then creating a new slice
with a longer length, offset from the base structure pointer instead.
This makes some choices of Rust semantics happier.
-rw-r--r--library/std/src/sys/windows/io.rs8
1 files changed, 4 insertions, 4 deletions
diff --git a/library/std/src/sys/windows/io.rs b/library/std/src/sys/windows/io.rs
index 0ec61931563..7e7518b6d89 100644
--- a/library/std/src/sys/windows/io.rs
+++ b/library/std/src/sys/windows/io.rs
@@ -132,10 +132,10 @@ unsafe fn msys_tty_on(handle: c::HANDLE) -> bool {
         return false;
     }
     let name_info: &c::FILE_NAME_INFO = &*(name_info_bytes.as_ptr() as *const c::FILE_NAME_INFO);
-    let s = core::slice::from_raw_parts(
-        name_info.FileName.as_ptr(),
-        name_info.FileNameLength as usize / 2,
-    );
+    let name_len = name_info.FileNameLength as usize / 2;
+    // Offset to get the `FileName` field.
+    let name_ptr = name_info_bytes.as_ptr().offset(size_of::<c::DWORD>() as isize).cast::<u16>();
+    let s = core::slice::from_raw_parts(name_ptr, name_len);
     let name = String::from_utf16_lossy(s);
     // This checks whether 'pty' exists in the file name, which indicates that
     // a pseudo-terminal is attached. To mitigate against false positives