about summary refs log tree commit diff
path: root/src/libstd/sys/windows
diff options
context:
space:
mode:
authordiaphore <diaphore@gmail.com>2015-08-06 22:44:50 +0200
committerdiaphore <diaphore@gmail.com>2015-08-07 03:49:31 +0200
commit2daa1b75309be4c98e5614d2fac089b246d6ba79 (patch)
treeb72c7ac853c39e98a3851e8c633d2bdce9865516 /src/libstd/sys/windows
parentfb92de75c1c4b7eaaf5d425fb2587407c00701fc (diff)
downloadrust-2daa1b75309be4c98e5614d2fac089b246d6ba79.tar.gz
rust-2daa1b75309be4c98e5614d2fac089b246d6ba79.zip
Trim trailing newline from FormatMessageW
Diffstat (limited to 'src/libstd/sys/windows')
-rw-r--r--src/libstd/sys/windows/os.rs10
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),
         }