Deal with invalid UTF-8 from gai_strerror
· model-checking/verify-rust-std@321dbf8 (original) (raw)
`@@ -4,7 +4,6 @@ use crate::io::{self, BorrowedBuf, BorrowedCursor, IoSlice, IoSliceMut};
`
4
4
`use crate::mem;
`
5
5
`use crate:🥅:{Shutdown, SocketAddr};
`
6
6
`use crate::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd};
`
7
``
`-
use crate::str;
`
8
7
`use crate::sys::fd::FileDesc;
`
9
8
`use crate::sys::pal::unix::IsMinusOne;
`
10
9
`use crate::sys_common:🥅:{getsockopt, setsockopt, sockaddr_to_addr};
`
`@@ -47,7 +46,9 @@ pub fn cvt_gai(err: c_int) -> io::Result<()> {
`
47
46
``
48
47
`#[cfg(not(target_os = "espidf"))]
`
49
48
`let detail = unsafe {
`
50
``
`-
str::from_utf8(CStr::from_ptr(libc::gai_strerror(err)).to_bytes()).unwrap().to_owned()
`
``
49
`+
// We can't always expect a UTF-8 environment. When we don't get that luxury,
`
``
50
`+
// it's better to give a low-quality error message than none at all.
`
``
51
`+
CStr::from_ptr(libc::gai_strerror(err)).to_string_lossy()
`
51
52
`};
`
52
53
``
53
54
`#[cfg(target_os = "espidf")]
`