-
Notifications
You must be signed in to change notification settings - Fork 206
Replace as
casts with safer conversions
#510
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,10 +24,16 @@ pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> { | |
// https://docs.rs/wasi/0.11.0+wasi-snapshot-preview1/src/wasi/lib_generated.rs.html#2046-2062 | ||
// Note that size of an allocated object can not be bigger than isize::MAX bytes. | ||
// WASI 0.1 supports only 32-bit WASM, so casting length to `i32` is safe. | ||
#[allow(clippy::cast_possible_truncation, clippy::cast_possible_wrap)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the only place for which we have to disable the lints. Unfortunately, the compiler does not use the requirement that non-ZST allocations can not be bigger than Also, IIRC WASI executors interprets |
||
let ret = unsafe { random_get(dest.as_mut_ptr() as i32, dest.len() as i32) }; | ||
match ret { | ||
0 => Ok(()), | ||
_ => Err(Error::from_os_error(ret as u32)), | ||
code => { | ||
let err = u32::try_from(code) | ||
.map(Error::from_os_error) | ||
.unwrap_or(Error::UNEXPECTED); | ||
Err(err) | ||
} | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This cast will be no longer needed if #508 lands.