Skip to content

Conversation

@RRRadicalEdward
Copy link
Collaborator

@RRRadicalEdward RRRadicalEdward commented Oct 17, 2025

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

num-derive = "0.4"
num-traits = "0.2"
crates.


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)
Copy link
Collaborator Author

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);
Copy link
Collaborator Author

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.

@github-actions
Copy link

github-actions bot commented Oct 17, 2025

Coverage Report 🤖 ⚙️

Past:
Total lines: 30127
Covered lines: 18759 (62.27%)

New:
Total lines: 30199
Covered lines: 18826 (62.34%)

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)) };
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with_exposed_provenance_mut:

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 {
Copy link
Collaborator Author

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 {
Copy link
Collaborator Author

@RRRadicalEdward RRRadicalEdward Oct 17, 2025

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

@RRRadicalEdward RRRadicalEdward self-assigned this Oct 17, 2025
@RRRadicalEdward
Copy link
Collaborator Author

@CBenoit could you review when you get a chance? We can improve this one slowly, but steadily.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants