-
Notifications
You must be signed in to change notification settings - Fork 252
Open
Description
Values like zero panic on raw and ignored on libc.
rustix/src/backend/linux_raw/io/errno.rs
Lines 80 to 97 in c4caf5c
| pub const fn from_raw_os_error(raw: i32) -> Self { | |
| Self::from_errno(raw as u32) | |
| } | |
| /// Convert from a C `errno` value (which is positive) to an `Errno`. | |
| const fn from_errno(raw: u32) -> Self { | |
| // We store error values in negated form, so that we don't have to | |
| // negate them after every syscall. | |
| let encoded = raw.wrapping_neg() as u16; | |
| // TODO: Use Range::contains, once that's `const`. | |
| assert!(encoded >= 0xf001); | |
| // SAFETY: Linux syscalls return negated error values in the range | |
| // `-4095..0`, which we just asserted. | |
| unsafe { Self(encoded) } | |
| } | |
| } |
rustix/src/backend/libc/io/errno.rs
Lines 1107 to 1109 in c4caf5c
| pub const fn from_raw_os_error(raw: i32) -> Self { | |
| Self(raw) | |
| } |
I think this behavior should be consistent, but also panic is bad, because it is on error path, so if something goes bad (and probably rare and hardly reproducible), panic would make harder to debug such problems or result in unnecessary avoidable crashes.
Probably reset wrong value to EINVAL or something?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels