Skip to content

Commit

Permalink
Use i32::unsigned_abs() instead of (-x) as u32.
Browse files Browse the repository at this point in the history
  • Loading branch information
briansmith committed May 29, 2024
1 parent 7d3fd32 commit 58f3c01
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/hermit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ pub fn getrandom_inner(mut dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
dest = &mut dest[res as usize..];
} else {
let err = match res {
MIN_RET_CODE..=-1 => NonZeroU32::new(-res as u32).unwrap().into(),
MIN_RET_CODE..=-1 => {
NonZeroU32::new(res.unsigned_abs()).map_or(Error::UNEXPECTED, Error::from)
}
_ => Error::UNEXPECTED,
};
return Err(err);
Expand Down
2 changes: 1 addition & 1 deletion src/solid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
} else {
// ITRON error numbers are always negative, so we negate it so that it
// falls in the dedicated OS error range (1..INTERNAL_START).
Err(NonZeroU32::new((-ret) as u32).unwrap().into())
Err(Error::from(NonZeroU32::new(ret.unsigned_abs()).unwrap()))
}
}

0 comments on commit 58f3c01

Please sign in to comment.