Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 255
Replace more casts with safer conversions & enable cast-related lints.#445
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
00105b2f0752e5782223d9f7ed6733051f5f35d5788aa2e41File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -208,6 +208,24 @@ | ||
| #![no_std] | ||
| #![warn(rust_2018_idioms, unused_lifetimes, missing_docs)] | ||
| #![cfg_attr(docsrs, feature(doc_auto_cfg))] | ||
| #![deny( | ||
| clippy::cast_lossless, | ||
| clippy::cast_possible_truncation, | ||
| clippy::cast_possible_wrap, | ||
| clippy::cast_precision_loss, | ||
| clippy::cast_ptr_alignment, | ||
| clippy::cast_sign_loss, | ||
| clippy::char_lit_as_u8, | ||
| clippy::checked_conversions, | ||
| clippy::fn_to_numeric_cast, | ||
| clippy::fn_to_numeric_cast_with_truncation, | ||
| clippy::ptr_as_ptr, | ||
| clippy::unnecessary_cast, | ||
| clippy::useless_conversion | ||
| )] | ||
Comment on lines
+211
to
+225
| ||
| // `clippy::cast_ref_to_mut` was replaced by `invalid_reference_casting` in 1.73. | ||
| #![allow(renamed_and_removed_lints)] | ||
| #![deny(clippy::cast_ref_to_mut)] | ||
| #[macro_use] | ||
| extern crate cfg_if; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -27,7 +27,9 @@ pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> { | ||
| // Prevent overflow of u32 | ||
| let chunk_size = usize::try_from(i32::MAX).expect("Windows does not support 16-bit targets"); | ||
| for chunk in dest.chunks_mut(chunk_size) { | ||
| let ret = unsafe { RtlGenRandom(chunk.as_mut_ptr().cast::<c_void>(), chunk.len() as u32) }; | ||
| #[allow(clippy::cast_possible_truncation)] | ||
| let chunk_len = chunk.len() as u32; | ||
Member 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. You can write it as | ||
| let ret = unsafe { RtlGenRandom(chunk.as_mut_ptr().cast::<c_void>(), chunk_len) }; | ||
| if ret != TRUE { | ||
| return Err(Error::WINDOWS_RTL_GEN_RANDOM); | ||
| } | ||
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.
You can use
.try_into().expect("..")here same as in windows7.