Skip to content

Conversation

RRRadicalEdward
Copy link
Collaborator

This lint

Checks for usage of indexing or slicing that may panic at runtime.

This one is quite pedantic and changes the way we write the code, but on the other hand, it makes the code more panic-resistant. Fixed the lint warnings only for ironrdp-web to see early feedback on it.
If we agree on adding it, I will add this lint for each crate separately, because there are too many warnings to do in 1 PR:
image

Copy link

github-actions bot commented Sep 21, 2025

Coverage Report 🤖 ⚙️

Past:
Total lines: 26124
Covered lines: 15317 (58.63%)

New:
Total lines: 26124
Covered lines: 15313 (58.62%)

Diff: -0.02%

[this comment will be updated automatically]

Comment on lines 46 to 49
let mut src = buffer.chunks_exact(4).map(|pixel| {
let r = pixel[0];
let g = pixel[1];
let b = pixel[2];
let r = *pixel.first().expect("index cannot be out of bounds");
let g = *pixel.get(1).expect("index cannot be out of bounds");
let b = *pixel.get(2).expect("index cannot be out of bounds");
Copy link
Member

Choose a reason for hiding this comment

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

Looks a bit too verbose, although there may be a better way to write this with the new stabilized APIs

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Do you have https://doc.rust-lang.org/std/primitive.slice.html#method.first_chunk in mind or something different? The perfect API here would be - https://doc.rust-lang.org/std/primitive.slice.html#method.as_array, but it's nightly only

Comment on lines +43 to +49
let src_slice = src.get(src_begin..src_end).with_context(|| {
format!(
"invalid region {region:?} for image with dimensions {}x{}",
image.width(),
image.height()
)
})?;
Copy link
Member

Choose a reason for hiding this comment

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

Preciously this was subject to panics upon bad input?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah. I think it was possible to trigger panic if passing an empty image and any valid region.

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

@CBenoit Does it look good? Should we proceed with adding this lint?

@CBenoit
Copy link
Member

CBenoit commented Oct 8, 2025

I want to double check a little bit more before merging this.

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.

2 participants