Skip to content

Commit

Permalink
Trim trailing newline from FormatMessageW
Browse files Browse the repository at this point in the history
  • Loading branch information
diaphore committed Aug 7, 2015
1 parent fb92de7 commit 2daa1b7
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/libstd/sys/windows/os.rs
Expand Up @@ -84,9 +84,13 @@ pub fn error_string(errnum: i32) -> String {
}

let b = buf.iter().position(|&b| b == 0).unwrap_or(buf.len());
let msg = String::from_utf16(&buf[..b]);
match msg {
Ok(msg) => msg,
match String::from_utf16(&buf[..b]) {
Ok(mut msg) => {
// Trim trailing CRLF inserted by FormatMessageW
let len = msg.trim_right().len();
msg.truncate(len);
msg
},
Err(..) => format!("OS Error {} (FormatMessageW() returned \
invalid UTF-16)", errnum),
}
Expand Down

0 comments on commit 2daa1b7

Please sign in to comment.