Skip to content

Commit cdd3f30

Browse files
build: allow windows-sys 0.59
1 parent c9b13f3 commit cdd3f30

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ features = ["all"]
3838
libc = "0.2.150"
3939

4040
[target.'cfg(windows)'.dependencies.windows-sys]
41-
version = "0.52"
41+
version = ">=0.52,<0.60"
4242
features = [
4343
"Win32_Foundation",
4444
"Win32_Networking_WinSock",

src/sys/windows.rs

+11
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,17 @@ pub(crate) fn unix_sockaddr(path: &Path) -> io::Result<SockAddr> {
926926
}
927927

928928
storage.sun_family = crate::sys::AF_UNIX as sa_family_t;
929+
930+
// `windows-sys` 0.52.* represents `SOCKADDR_UN::sun_path` as `&[u8]`, but 0.59.*
931+
// represents it as `&[i8]`.
932+
//
933+
// TODO: Remove this once `windows-sys` 0.52.* is no longer
934+
// permitted as a dependency.
935+
//
936+
// SAFETY: We are safe in doing this, because: `bytes` starts as `&[u8]`, and is converted
937+
// to a `&[u8]` or `&[i8]`, and all of these types have the same size and alignment.
938+
let bytes = unsafe { slice::from_raw_parts(bytes.as_ptr().cast(), bytes.len()) };
939+
929940
// `storage` was initialized to zero above, so the path is
930941
// already null terminated.
931942
storage.sun_path[..bytes.len()].copy_from_slice(bytes);

0 commit comments

Comments
 (0)