Skip to content

Commit 8e9c93d

Browse files
committed
Auto merge of rust-lang#99609 - workingjubilee:lossy-unix-strerror, r=thomcc
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. This fixes rust-lang#99535.
2 parents e20fabb + bcf780e commit 8e9c93d

File tree

1 file changed

+3
-1
lines changed
  • library/std/src/sys/unix

1 file changed

+3
-1
lines changed

library/std/src/sys/unix/os.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ pub fn error_string(errno: i32) -> String {
125125
}
126126

127127
let p = p as *const _;
128-
str::from_utf8(CStr::from_ptr(p).to_bytes()).unwrap().to_owned()
128+
// We can't always expect a UTF-8 environment. When we don't get that luxury,
129+
// it's better to give a low-quality error message than none at all.
130+
String::from_utf8_lossy(CStr::from_ptr(p).to_bytes()).into()
129131
}
130132
}
131133

0 commit comments

Comments
 (0)