diff options
| author | Jubilee Young <workingjubilee@gmail.com> | 2022-07-22 08:50:31 -0700 |
|---|---|---|
| committer | Jubilee Young <workingjubilee@gmail.com> | 2022-07-22 08:54:40 -0700 |
| commit | bcf780e2ba00dbe5a81502ef541dbc0f4fb76ebb (patch) | |
| tree | 95cdf7f7be8a4846fa43305a5cdb898495000feb /library/std/src | |
| parent | 246f66a905c2815f2c9b9c3d6b1e0649f3360ef8 (diff) | |
| download | rust-bcf780e2ba00dbe5a81502ef541dbc0f4fb76ebb.tar.gz rust-bcf780e2ba00dbe5a81502ef541dbc0f4fb76ebb.zip | |
Recover error strings on Unix from_lossy_utf8
Some language settings can result in unreliable UTF-8 being produced. This can result in failing to emit the error string, panicking instead. from_lossy_utf8 allows us to assume these strings usually will be fine.
Diffstat (limited to 'library/std/src')
| -rw-r--r-- | library/std/src/sys/unix/os.rs | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/library/std/src/sys/unix/os.rs b/library/std/src/sys/unix/os.rs index 7252ad32184..3009a9b1f01 100644 --- a/library/std/src/sys/unix/os.rs +++ b/library/std/src/sys/unix/os.rs @@ -125,7 +125,9 @@ pub fn error_string(errno: i32) -> String { } let p = p as *const _; - str::from_utf8(CStr::from_ptr(p).to_bytes()).unwrap().to_owned() + // We can't always expect a UTF-8 environment. When we don't get that luxury, + // it's better to give a low-quality error message than none at all. + String::from_utf8_lossy(CStr::from_ptr(p).to_bytes()).into() } } |
