diff options
| author | Simonas Kazlauskas <git@kazlauskas.me> | 2015-08-25 18:26:29 +0300 |
|---|---|---|
| committer | Simonas Kazlauskas <git@kazlauskas.me> | 2015-08-25 18:33:39 +0300 |
| commit | c4c533a2935f1e39ef94920d9f1430ba75c69376 (patch) | |
| tree | 0dff24b06a98017e2391a565c1141afd22ee6124 | |
| parent | 2b45a0d90853deca584a28a55237d996a274a833 (diff) | |
| download | rust-c4c533a2935f1e39ef94920d9f1430ba75c69376.tar.gz rust-c4c533a2935f1e39ef94920d9f1430ba75c69376.zip | |
Do not recalculate string length in error_string
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.
| -rw-r--r-- | src/libstd/sys/windows/os.rs | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/src/libstd/sys/windows/os.rs b/src/libstd/sys/windows/os.rs index 694d873d0d2..bf56aaa277e 100644 --- a/src/libstd/sys/windows/os.rs +++ b/src/libstd/sys/windows/os.rs @@ -75,7 +75,7 @@ pub fn error_string(errnum: i32) -> String { langId, buf.as_mut_ptr(), buf.len() as DWORD, - ptr::null()); + ptr::null()) as usize; if res == 0 { // Sometimes FormatMessageW can fail e.g. system doesn't like langId, let fm_err = errno(); @@ -83,8 +83,7 @@ pub fn error_string(errnum: i32) -> String { errnum, fm_err); } - let b = buf.iter().position(|&b| b == 0).unwrap_or(buf.len()); - match String::from_utf16(&buf[..b]) { + match String::from_utf16(&buf[..res]) { Ok(mut msg) => { // Trim trailing CRLF inserted by FormatMessageW let len = msg.trim_right().len(); |
