diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2015-08-11 13:26:46 +0530 |
|---|---|---|
| committer | Manish Goregaokar <manishsmail@gmail.com> | 2015-08-11 16:48:01 +0530 |
| commit | be2d4fbcb0208a8853de1da5961d31a86e1efdc2 (patch) | |
| tree | 5ad79c75af24bf086c806546b46fcfa4573f9a03 /src/libstd/sys/windows | |
| parent | 2cad6fef60b0a624ac5576a4fe10e871690cce75 (diff) | |
| parent | 2daa1b75309be4c98e5614d2fac089b246d6ba79 (diff) | |
| download | rust-be2d4fbcb0208a8853de1da5961d31a86e1efdc2.tar.gz rust-be2d4fbcb0208a8853de1da5961d31a86e1efdc2.zip | |
Rollup merge of #27577 - diaphore:trailing-newline-formatmessagew, r=alexcrichton
`FormatMessageW` always inserts trailing `\r\n` to system messages which is a minor annoyance when they're fed to `Debug` but can break formatting with `Display`.
```rust
fn main() {
use std::env;
if let Err(err) = env::set_current_dir("???") {
println!("{:#?}\n{}", err, err);
}
}
```
```_
Error {
repr: Os {
code: 2,
message: "The system cannot find the file specified.\r\n"
}
}
The system cannot find the file specified.
(os error 2)
```
Diffstat (limited to 'src/libstd/sys/windows')
| -rw-r--r-- | src/libstd/sys/windows/os.rs | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/libstd/sys/windows/os.rs b/src/libstd/sys/windows/os.rs index 8a8cf9e7c53..694d873d0d2 100644 --- a/src/libstd/sys/windows/os.rs +++ b/src/libstd/sys/windows/os.rs @@ -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), } |
