Skip to content

Commit 4c05a91

Browse files
committed
Update from code review
1 parent 9be8b3a commit 4c05a91

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

Diff for: library/std/src/sys/path/windows.rs

+1
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ pub(crate) fn is_absolute_exact(path: &[u16]) -> bool {
386386
if result == 0 || result as usize != buffer_len - 1 {
387387
false
388388
} else {
389+
// SAFETY: `GetFullPathNameW` initialized `result` bytes and does not exceed `nBufferLength - 1` (capacity).
389390
unsafe {
390391
new_path.set_len((result as usize) + 1);
391392
}

Diff for: library/std/src/sys/path/windows/tests.rs

+3
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,7 @@ fn test_is_absolute_exact() {
146146
assert!(!is_absolute_exact(wide_str!(r"C:\path\to\..\file")));
147147
assert!(!is_absolute_exact(wide_str!(r"\\server\share\path\to\..\file")));
148148
assert!(!is_absolute_exact(wide_str!(r"C:\path\to\NUL"))); // Converts to \\.\NUL
149+
assert!(!is_absolute_exact(wide_str!(r"C:\path\to\COM1"))); // Converts to \\.\NUL
150+
assert!(!is_absolute_exact(wide_str!(r"C:\path\to\CON"))); // Converts to \\.\NUL
151+
assert!(!is_absolute_exact(wide_str!(r"C:\path\to\AUX"))); // Converts to \\.\NUL
149152
}

Diff for: library/std/src/sys/process/windows.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ fn make_dirp(d: Option<&OsString>) -> io::Result<(*const u16, Vec<u16>)> {
889889
let start = r"\\?\UN".len();
890890
dir_str[start] = b'\\' as u16;
891891
if path::is_absolute_exact(&dir_str[start..]) {
892-
unsafe { dir_str.as_ptr().add(start) }
892+
dir_str[start..].as_ptr()
893893
} else {
894894
// Revert the above change.
895895
dir_str[start] = b'C' as u16;
@@ -899,7 +899,7 @@ fn make_dirp(d: Option<&OsString>) -> io::Result<(*const u16, Vec<u16>)> {
899899
// Strip the leading `\\?\`
900900
let start = r"\\?\".len();
901901
if path::is_absolute_exact(&dir_str[start..]) {
902-
unsafe { dir_str.as_ptr().add(start) }
902+
dir_str[start..].as_ptr()
903903
} else {
904904
dir_str.as_ptr()
905905
}

0 commit comments

Comments
 (0)