- 
                Notifications
    You must be signed in to change notification settings 
- Fork 138
          refactor: add as_conversions clippy correctness lint
          #1021
        
          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
base: master
Are you sure you want to change the base?
  
    refactor: add as_conversions clippy correctness lint
  
  #1021
              Conversation
|  | ||
| fn delta_value(prev: u8, next: u8) -> u8 { | ||
| let mut result = (next as i16 - prev as i16) as u8; | ||
| let mut result = u8::try_from((i16::from(next) - i16::from(prev)) & 0xFF) | 
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 could underflow, so I made it safe with masking.
| let top_virtual = y as i16 - pointer.hotspot_y as i16; | ||
| let right_virtual = left_virtual + pointer.width as i16 - 1; | ||
| let bottom_virtual = top_virtual + pointer.height as i16 - 1; | ||
| let left_virtual = i32::from(x) - i32::from(pointer.hotspot_x); | 
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.
casting to i32 instead of i16 so that u16 can fit into.
| Coverage Report 🤖 ⚙️Past: New: Diff: +0.07% [this comment will be updated automatically] | 
| // SAFETY: `data` is a valid pointer, returned by `Box::into_raw`, transferred to OS earlier | ||
| // via `SetWindowSubclass` call. | ||
| let _ = unsafe { Box::from_raw(data as *mut WinClipboardImpl) }; | ||
| let _ = unsafe { Box::from_raw(with_exposed_provenance_mut::<WinClipboardImpl>(data)) }; | 
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.
Converts an address back to a mutable pointer, picking up some previously ‘exposed’ provenance.
This is fully equivalent to addr as *mut T. The provenance of the returned pointer is that of some pointer that was previously exposed by passing it to expose_provenance, or a ptr as usize cast
|  | ||
| #[expect(clippy::as_conversions)] | ||
| #[expect(clippy::cast_possible_truncation)] | ||
| fn i32_to_i16_possible_truncation(value: i32) -> i16 { | 
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.
Added this helper usage, which performs as operations under the hood in this file, because value manipulations in this module are quite tricky, and I don't want to break anything. So go with a safe option here.
| } | ||
| } | ||
|  | ||
| impl From<MinorFunction> for u8 { | 
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.
There is already:
impl From<MinorFunction> for u32 {
    fn from(minor_function: MinorFunction) -> Self {
        minor_function.0
    }
}which does the same
| @CBenoit could you review when you get a chance? We can improve this one slowly, but steadily. | 
I worked on this one by doing a little every day. This will help with getting rid of
IronRDP/Cargo.toml
Lines 43 to 44 in 52225cc