Uh oh!
There was an error while loading. Please reload this page.
Remove use of locale-specific strerror_r. - #440
Conversation
| // Take up to trailing null byte | ||
| let n = buf.len(); | ||
| let idx = buf.iter().position(|&b| b == 0).unwrap_or(n); | ||
| core::str::from_utf8(&buf[..idx]).ok() |
There was a problem hiding this comment.
Even if the bytes do not contain any invalid UTF-8 sequences, they might not be encoding UTF-8.
There was a problem hiding this comment.
Is there an actual example of this being an issue on a unix target?
There was a problem hiding this comment.
No offense, but I don't participate in that kind of thinking. Instead it would be better to have a proof that it isn't an issue.
There was a problem hiding this comment.
Oh no offense taken, I think this is a good point (especially when it comes to stuff like the safety of code or cryptographic security where I 100% agree). Sorry for being a little short. I just meant to note that an implementation returning UTF8 bytes that aren't UTF8 only causes the display implementation to show a suboptimal error string.
However, after looking more into strerror_r, I agree that we shouldn't be assuming that it is well behaved on arbitrary unix targets. This is libstd's job, not ours. See my suggestion below.
Edit: I think we can actually remove use of |
josephlr
commented
May 30, 2024
After looking at this some more (and reading more about impl fmt::DisplayforError{fnfmt(&self,f:&mutFormatter){ifletSome(errno) = self.raw_os_error(){#[cfg(feature = "std")]
std::io::Error::from_raw_os_error(error).fmt(f)#[cfg(not(feature = "std"))]write!(f,"OS error {}", errno)}else{
...}}} |
newpavlov
commented
May 30, 2024
I agree with the @josephlr's suggestion above. |
briansmith
commented
May 31, 2024
This would mean that the output would depend on the |
Arguably, the main reason for the |
strerror_r doesn't necessarily return UTF-8 but we assume it does. strerror_r is locale-sensitive but we are better off not being locale-sensitive. strerror_r requires us to use libc but increasingly we want to avoid libc, e.g. to support x86_64-unknown-linux-none. Just remove the use of the function.
strerror_r doesn't necessarily return UTF-8 but we assume it does. strerror_r is locale-sensitive but we are better off not being locale-sensitive. strerror_r requires us to use libc but increasingly we want to avoid libc, e.g. to support x86_64-unknown-linux-none. Just remove the use of the function.
Tweak the breaking changes section and add entries for rust-random#415, rust-random#440, rust-random#442, rust-random#448, rust-random#504, and rust-random#512.
strerror_r doesn't necessarily return UTF-8 but we assume it does.
strerror_r is locale-sensitive but we are better off not being locale-sensitive.
strerror_r requires us to use libc but increasingly we want to avoid libc, e.g. to support x86_64-unknown-linux-none.
Just remove the use of the function.