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.
This commit is contained in:
parent
e25fe564d1
commit
6a79da9ab7
@ -132,10 +132,10 @@ unsafe fn msys_tty_on(handle: c::HANDLE) -> bool {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
let name_info: &c::FILE_NAME_INFO = &*(name_info_bytes.as_ptr() as *const c::FILE_NAME_INFO);
|
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(
|
let name_len = name_info.FileNameLength as usize / 2;
|
||||||
name_info.FileName.as_ptr(),
|
// Offset to get the `FileName` field.
|
||||||
name_info.FileNameLength as usize / 2,
|
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);
|
let name = String::from_utf16_lossy(s);
|
||||||
// This checks whether 'pty' exists in the file name, which indicates that
|
// This checks whether 'pty' exists in the file name, which indicates that
|
||||||
// a pseudo-terminal is attached. To mitigate against false positives
|
// a pseudo-terminal is attached. To mitigate against false positives
|
||||||
|
Loading…
x
Reference in New Issue
Block a user