Skip to content

Commit d2cceb7

Browse files
committed
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.
1 parent 489b73b commit d2cceb7

File tree

1 file changed

+4
-4
lines changed
  • library/std/src/sys/windows

1 file changed

+4
-4
lines changed

library/std/src/sys/windows/io.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ unsafe fn msys_tty_on(handle: c::HANDLE) -> bool {
132132
return false;
133133
}
134134
let name_info: &c::FILE_NAME_INFO = &*(name_info_bytes.as_ptr() as *const c::FILE_NAME_INFO);
135-
let s = core::slice::from_raw_parts(
136-
name_info.FileName.as_ptr(),
137-
name_info.FileNameLength as usize / 2,
138-
);
135+
let name_len = name_info.FileNameLength as usize / 2;
136+
// Offset to get the `FileName` field.
137+
let name_ptr = name_info_bytes.as_ptr().offset(size_of::<c::DWORD>() as isize).cast::<u16>();
138+
let s = core::slice::from_raw_parts(name_ptr, name_len);
139139
let name = String::from_utf16_lossy(s);
140140
// This checks whether 'pty' exists in the file name, which indicates that
141141
// a pseudo-terminal is attached. To mitigate against false positives

0 commit comments

Comments
 (0)