Skip to content

Commit

Permalink
fix nodename string conversion (fixes #32)
Browse files Browse the repository at this point in the history
  • Loading branch information
rivy committed Jan 26, 2023
1 parent e9b80f0 commit 15a2a0f
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use self::winapi::um::winnt::*;
use self::winapi::um::winver::*;
use super::Uname;
use std::borrow::Cow;
use std::convert::TryFrom;
use std::ffi::{CStr, OsStr, OsString};
use std::io;
use std::iter;
Expand Down Expand Up @@ -105,7 +106,9 @@ impl PlatformInfo {
let mut data: Vec<u16> = vec![0; size as usize];
unsafe {
if GetComputerNameExW(ComputerNameDnsHostname, data.as_mut_ptr(), &mut size) != 0 {
Ok(String::from_utf16_lossy(&data))
Ok(String::from_utf16_lossy(
&data[..usize::try_from(size).unwrap()],
))
} else {
// XXX: should this error or just return localhost?
Err(io::Error::last_os_error())
Expand Down

0 comments on commit 15a2a0f

Please sign in to comment.