Closed
Description
Lines 4 to 7 in 35808a4
Lines 9 to 16 in 35808a4
- If
res == -sizie::MIN
then(-res)
will overflow. To fix, usechecked_neg()
. - if
res < (i32::MIN as isize)
then(-res) as u32
is a truncating, i.e. lossy conversion. To fix: avoid usingas
for integer conversions and instead useTryInto
for this conversion. - if
(-res) % 0x1_0000_0000 == 0
then(-res) as u32
is zero and thenNonZeroU32::new_unchecked((-res) as u32)
is undefined behavior. To fix, use the safeNonZerou32::new()
instead.
Maybe somewhere hermit guarantees errors codes will never be this large but better to avoid the issue completely.
Something like:
let code = res.checked_neg().map(u32::try_from).map(NonZeroU32::new).unwrap_or(something);
There would be no undefined behavior in the new version.
Metadata
Metadata
Assignees
Labels
No labels