Skip to content

Commit

Permalink
auto merge of #13078 : klutzy/rust/issue-13075, r=alexcrichton
Browse files Browse the repository at this point in the history
`FormatMessageW()` is called by `std::os::last_os_error()` to convert
errno into string, but the function may fail on non-english locale.
I don't know why it fails, but anyway it's better to return errno
than to `fail!()` in the case.

Fixes #13075
Fixes #13073
  • Loading branch information
bors committed Mar 22, 2014
2 parents e233a43 + cffe9e0 commit 5e8e1b5
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/libstd/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -740,11 +740,16 @@ pub fn last_os_error() -> ~str {
buf.len() as DWORD,
ptr::null());
if res == 0 {
fail!("[{}] FormatMessage failure", errno());
// Sometimes FormatMessageW can fail e.g. system doesn't like langId,
let fm_err = errno();
return format!("OS Error {} (FormatMessageW() returned error {})", err, fm_err);
}

str::from_utf16(str::truncate_utf16_at_nul(buf))
.expect("FormatMessageW returned invalid UTF-16")
let msg = str::from_utf16(str::truncate_utf16_at_nul(buf));
match msg {
Some(msg) => format!("OS Error {}: {}", err, msg),
None => format!("OS Error {} (FormatMessageW() returned invalid UTF-16)", err),
}
}
}

Expand Down

0 comments on commit 5e8e1b5

Please sign in to comment.