]> git.lizzy.rs Git - rust.git/blobdiff - library/std/src/sys/unix/os.rs
Recover error strings on Unix from_lossy_utf8
[rust.git] / library / std / src / sys / unix / os.rs
index 7252ad321844bd3b72c3e033cbe87b093f4c7e2e..3009a9b1f01ca2ff1f9c266155b9c6b99e4f6be3 100644 (file)
@@ -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()
     }
 }