Skip to content

Commit b339f38

Browse files
committed
Auto merge of #27995 - nagisa:windows-error-message, r=alexcrichton
According to https://msdn.microsoft.com/en-us/library/windows/desktop/ms679351(v=vs.85).aspx: > If the function succeeds, the return value is the number of TCHARs stored in the output buffer, > excluding the terminating null character. _**Completely untested**_… since I have no Windows machine or anything of a sort to test this on. r? @aturon
2 parents 1806174 + c4c533a commit b339f38

File tree

1 file changed

+2
-3
lines changed
  • src/libstd/sys/windows

1 file changed

+2
-3
lines changed

Diff for: src/libstd/sys/windows/os.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,15 @@ pub fn error_string(errnum: i32) -> String {
7474
langId,
7575
buf.as_mut_ptr(),
7676
buf.len() as DWORD,
77-
ptr::null());
77+
ptr::null()) as usize;
7878
if res == 0 {
7979
// Sometimes FormatMessageW can fail e.g. system doesn't like langId,
8080
let fm_err = errno();
8181
return format!("OS Error {} (FormatMessageW() returned error {})",
8282
errnum, fm_err);
8383
}
8484

85-
let b = buf.iter().position(|&b| b == 0).unwrap_or(buf.len());
86-
match String::from_utf16(&buf[..b]) {
85+
match String::from_utf16(&buf[..res]) {
8786
Ok(mut msg) => {
8887
// Trim trailing CRLF inserted by FormatMessageW
8988
let len = msg.trim_right().len();

0 commit comments

Comments
 (0)