mirror of
https://github.com/netbirdio/IronRDP.git
synced 2026-05-22 18:43:12 -07:00
refactor: add allow_attributes clippy to "Extra-pedantic clippy" section (#880)
This commit is contained in:
@@ -124,6 +124,7 @@ string_lit_chars_any = "warn"
|
||||
unnecessary_box_returns = "warn"
|
||||
|
||||
# == Extra-pedantic clippy == #
|
||||
allow_attributes = "warn"
|
||||
collection_is_never_read = "warn"
|
||||
copy_iterator = "warn"
|
||||
expl_impl_clone_on_copy = "warn"
|
||||
|
||||
@@ -404,7 +404,7 @@ impl Sequence for Acceptor {
|
||||
})
|
||||
.unwrap_or_default();
|
||||
|
||||
#[allow(clippy::arithmetic_side_effects)] // IO channel ID is not big enough for overflowing.
|
||||
#[expect(clippy::arithmetic_side_effects)] // IO channel ID is not big enough for overflowing.
|
||||
let channels = joined
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
|
||||
@@ -32,7 +32,7 @@ pub enum BitmapError {
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
struct BitmapCompression(u32);
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[expect(dead_code)]
|
||||
impl BitmapCompression {
|
||||
const RGB: Self = Self(0x0000);
|
||||
const RLE8: Self = Self(0x0001);
|
||||
@@ -48,7 +48,7 @@ impl BitmapCompression {
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
struct ColorSpace(u32);
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[expect(dead_code)]
|
||||
impl ColorSpace {
|
||||
const CALIBRATED_RGB: Self = Self(0x00000000);
|
||||
const SRGB: Self = Self(0x73524742);
|
||||
@@ -60,7 +60,7 @@ impl ColorSpace {
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
struct BitmapIntent(u32);
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[expect(dead_code)]
|
||||
impl BitmapIntent {
|
||||
const LCS_GM_ABS_COLORIMETRIC: Self = Self(0x00000008);
|
||||
const LCS_GM_BUSINESS: Self = Self(0x00000001);
|
||||
@@ -499,7 +499,7 @@ fn rgb_bmp_stride(width: u16, bit_count: u16) -> usize {
|
||||
debug_assert!(bit_count <= 32);
|
||||
|
||||
// No side effects, because u16::MAX * 32 + 31 < u16::MAX * u16::MAX < u32::MAX
|
||||
#[allow(clippy::arithmetic_side_effects)]
|
||||
#[expect(clippy::arithmetic_side_effects)]
|
||||
{
|
||||
(((usize::from(width) * usize::from(bit_count)) + 31) & !31) >> 3
|
||||
}
|
||||
@@ -527,7 +527,7 @@ fn bgra_to_top_down_rgba(
|
||||
};
|
||||
|
||||
// Per invariants: height * width * dst_n_samples <= 10_000 * 10_000 * 4 < u32::MAX
|
||||
#[allow(clippy::arithmetic_side_effects)]
|
||||
#[expect(clippy::arithmetic_side_effects)]
|
||||
let dst_bitmap_len = usize::from(height) * usize::from(width) * dst_n_samples;
|
||||
|
||||
// Prevent allocation of huge buffers.
|
||||
@@ -569,7 +569,7 @@ fn bgra_to_top_down_rgba(
|
||||
};
|
||||
|
||||
// Per invariants: width * dst_n_samples <= 10_000 * 4 < u32::MAX
|
||||
#[allow(clippy::arithmetic_side_effects)]
|
||||
#[expect(clippy::arithmetic_side_effects)]
|
||||
let dst_stride = usize::from(width) * dst_n_samples;
|
||||
|
||||
let mut dst_bitmap = vec![0u8; dst_bitmap_len];
|
||||
@@ -647,13 +647,13 @@ fn top_down_rgba_to_bottom_up_bgra(
|
||||
let width = u16::try_from(info.width).map_err(|_| BitmapError::WidthTooBig)?;
|
||||
let height = u16::try_from(info.height).map_err(|_| BitmapError::HeightTooBig)?;
|
||||
|
||||
#[allow(clippy::arithmetic_side_effects)] // width * 4 <= 10_000 * 4 < u32::MAX
|
||||
#[expect(clippy::arithmetic_side_effects)] // width * 4 <= 10_000 * 4 < u32::MAX
|
||||
let stride = usize::from(width) * 4;
|
||||
|
||||
let src_rows = src_bitmap.chunks_exact(stride);
|
||||
|
||||
// As per invariants: stride * height <= width * 4 * height <= 10_000 * 4 * 10_000 <= u32::MAX.
|
||||
#[allow(clippy::arithmetic_side_effects)]
|
||||
#[expect(clippy::arithmetic_side_effects)]
|
||||
let dst_len = stride * usize::from(height);
|
||||
let dst_len = u32::try_from(dst_len).map_err(|_| BitmapError::InvalidSize)?;
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ pub fn plain_html_to_cf_html(fragment: &str) -> String {
|
||||
let mut write_header = |key: &str, value: &str| {
|
||||
// This relation holds: key.len() + value.len() + ":\r\n".len() < usize::MAX
|
||||
// Rationale: we know all possible values (see code below), and they are much smaller than `usize::MAX`.
|
||||
#[allow(clippy::arithmetic_side_effects)]
|
||||
#[expect(clippy::arithmetic_side_effects)]
|
||||
let size = key.len() + value.len() + ":\r\n".len();
|
||||
buffer.reserve(size);
|
||||
|
||||
@@ -136,7 +136,7 @@ pub fn plain_html_to_cf_html(fragment: &str) -> String {
|
||||
let mut replace_placeholder = |value_begin_idx: usize, header_value: &str| {
|
||||
// We know that: value_begin_idx + POS_PLACEHOLDER.len() < usize::MAX
|
||||
// Rationale: the headers are written at the beginning, and we’re not indexing outside of the string.
|
||||
#[allow(clippy::arithmetic_side_effects)]
|
||||
#[expect(clippy::arithmetic_side_effects)]
|
||||
let value_end_idx = value_begin_idx + POS_PLACEHOLDER.len();
|
||||
|
||||
buffer.replace_range(value_begin_idx..value_end_idx, header_value);
|
||||
|
||||
@@ -261,7 +261,7 @@ impl WinClipboardImpl {
|
||||
const MAX_PROCESSING_ATTEMPTS: u32 = 10;
|
||||
const PROCESSING_TIMEOUT_MS: u32 = 100;
|
||||
|
||||
#[allow(clippy::arithmetic_side_effects)]
|
||||
#[expect(clippy::arithmetic_side_effects)]
|
||||
// self.attempt can’t be greater than MAX_PROCESSING_ATTEMPTS, so the arithmetic is safe here
|
||||
if self.attempt < MAX_PROCESSING_ATTEMPTS {
|
||||
self.attempt += 1;
|
||||
@@ -347,7 +347,7 @@ pub(crate) unsafe extern "system" fn clipboard_subproc(
|
||||
}
|
||||
// Sent by the OS when delay-rendered data is requested for rendering.
|
||||
WM_RENDERFORMAT => {
|
||||
#[allow(clippy::cast_possible_truncation)] // should never truncate in practice
|
||||
#[expect(clippy::cast_possible_truncation)] // should never truncate in practice
|
||||
ctx.handle_event(BackendEvent::RenderFormat(ClipboardFormatId::new(wparam.0 as u32)));
|
||||
}
|
||||
// Sent by the OS when all delay-rendered data is requested for rendering.
|
||||
|
||||
@@ -19,7 +19,7 @@ impl OwnedOsClipboard {
|
||||
}
|
||||
|
||||
/// Enumerates all available formats in the current clipboard.
|
||||
#[allow(clippy::unused_self)] // ensure we own the clipboard using RAII, and exclusive &mut self reference
|
||||
#[expect(clippy::unused_self)] // ensure we own the clipboard using RAII, and exclusive &mut self reference
|
||||
pub(crate) fn enum_available_formats(&mut self) -> Result<Vec<ClipboardFormat>, WinCliprdrError> {
|
||||
const DEFAULT_FORMATS_CAPACITY: usize = 16;
|
||||
// Sane default for format name. If format name is longer than this,
|
||||
@@ -74,7 +74,7 @@ impl OwnedOsClipboard {
|
||||
/// Empties the clipboard
|
||||
///
|
||||
/// It is required to empty clipboard before setting any delay-rendered data.
|
||||
#[allow(clippy::unused_self)] // ensure we own the clipboard using RAII, and exclusive &mut self reference
|
||||
#[expect(clippy::unused_self)] // ensure we own the clipboard using RAII, and exclusive &mut self reference
|
||||
pub(crate) fn clear(&mut self) -> Result<(), WinCliprdrError> {
|
||||
// SAFETY: We own the clipboard at moment of method invocation, therefore it is safe to
|
||||
// call `EmptyClipboard`.
|
||||
@@ -83,7 +83,7 @@ impl OwnedOsClipboard {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[allow(clippy::unused_self)] // ensure we own the clipboard using RAII, and exclusive &mut self reference
|
||||
#[expect(clippy::unused_self)] // ensure we own the clipboard using RAII, and exclusive &mut self reference
|
||||
pub(crate) fn delay_render(&mut self, format: ClipboardFormatId) -> Result<(), WinCliprdrError> {
|
||||
// SAFETY: We own the clipboard at moment of method invocation, therefore it is safe to
|
||||
// call `SetClipboardData`.
|
||||
|
||||
@@ -600,7 +600,7 @@ pub fn encode_send_data_request<T: Encode>(
|
||||
Ok(written)
|
||||
}
|
||||
|
||||
#[allow(single_use_lifetimes)] // anonymous lifetimes in `impl Trait` are unstable
|
||||
#[expect(single_use_lifetimes)] // anonymous lifetimes in `impl Trait` are unstable
|
||||
fn create_gcc_blocks<'a>(
|
||||
config: &Config,
|
||||
selected_protocol: nego::SecurityProtocol,
|
||||
|
||||
@@ -44,7 +44,7 @@ impl Encode for DisplayControlPdu {
|
||||
};
|
||||
|
||||
// This will never overflow as per invariants.
|
||||
#[allow(clippy::arithmetic_side_effects)]
|
||||
#[expect(clippy::arithmetic_side_effects)]
|
||||
let pdu_size = payload_length + Self::FIXED_PART_SIZE;
|
||||
|
||||
// Write `DISPLAYCONTROL_HEADER` fields.
|
||||
@@ -65,7 +65,7 @@ impl Encode for DisplayControlPdu {
|
||||
|
||||
fn size(&self) -> usize {
|
||||
// As per invariants: This will never overflow.
|
||||
#[allow(clippy::arithmetic_side_effects)]
|
||||
#[expect(clippy::arithmetic_side_effects)]
|
||||
let size = Self::FIXED_PART_SIZE
|
||||
+ match self {
|
||||
DisplayControlPdu::Caps(caps) => caps.size(),
|
||||
@@ -310,7 +310,7 @@ impl Encode for DisplayControlMonitorLayout {
|
||||
fn size(&self) -> usize {
|
||||
// As per invariants: This will never overflow:
|
||||
// 0 <= Self::FIXED_PART_SIZE + MAX_SUPPORTED_MONITORS * MonitorLayoutEntry::FIXED_PART_SIZE < u16::MAX
|
||||
#[allow(clippy::arithmetic_side_effects)]
|
||||
#[expect(clippy::arithmetic_side_effects)]
|
||||
let size = Self::FIXED_PART_SIZE + self.monitors.iter().map(|monitor| monitor.size()).sum::<usize>();
|
||||
|
||||
size
|
||||
@@ -751,6 +751,6 @@ fn calculate_monitor_area(
|
||||
|
||||
// As per invariants: This multiplication would never overflow.
|
||||
// 0 <= MAX_MONITOR_AREA_FACTOR * MAX_MONITOR_AREA_FACTOR * MAX_SUPPORTED_MONITORS <= u64::MAX
|
||||
#[allow(clippy::arithmetic_side_effects)]
|
||||
#[expect(clippy::arithmetic_side_effects)]
|
||||
Ok(u64::from(max_monitor_area_factor_a) * u64::from(max_monitor_area_factor_b) * u64::from(max_num_monitors))
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ impl Event {
|
||||
// CreateEventW returns a valid handle on success.
|
||||
Ok(Self {
|
||||
// See `unsafe impl Send` comment.
|
||||
#[allow(clippy::arc_with_non_send_sync)]
|
||||
#[expect(clippy::arc_with_non_send_sync)]
|
||||
handle: Arc::new(handle),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ impl Semaphore {
|
||||
Ok(Self {
|
||||
// See `unsafe impl Send` comment.
|
||||
// TODO(@CBenoit): Verify this comment.
|
||||
#[allow(clippy::arc_with_non_send_sync)]
|
||||
#[expect(clippy::arc_with_non_send_sync)]
|
||||
handle: Arc::new(handle),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ pub fn ycbcr_to_rgba(input: YCbCrBuffer<'_>, output: &mut [u8]) -> io::Result<()
|
||||
rdp_yuv444_to_rgba(&planar, output, len).map_err(io::Error::other)
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
#[expect(clippy::too_many_arguments)]
|
||||
pub fn to_64x64_ycbcr_tile(
|
||||
input: &[u8],
|
||||
width: usize,
|
||||
|
||||
@@ -184,7 +184,7 @@ fn find_different_rects<const BPP: usize>(
|
||||
/// │ │
|
||||
/// └───────────────────────────────────────────┘
|
||||
/// ```
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
#[expect(clippy::too_many_arguments)]
|
||||
pub fn find_different_rects_sub<const BPP: usize>(
|
||||
image1: &[u8],
|
||||
stride1: usize,
|
||||
|
||||
@@ -78,7 +78,7 @@ impl Scancode {
|
||||
pub const fn from_u16(scancode: u16) -> Self {
|
||||
let extended = scancode & 0xE000 == 0xE000;
|
||||
|
||||
#[allow(clippy::cast_possible_truncation)] // truncating on purpose
|
||||
#[expect(clippy::cast_possible_truncation)] // truncating on purpose
|
||||
let code = scancode as u8;
|
||||
|
||||
Self { code, extended }
|
||||
|
||||
@@ -3,14 +3,13 @@ use ironrdp_core::{cast_length, ensure_size, invalid_field_err, ReadCursor, Writ
|
||||
use crate::{DecodeResult, EncodeResult};
|
||||
|
||||
#[repr(u8)]
|
||||
#[allow(unused)]
|
||||
pub(crate) enum Pc {
|
||||
Primitive = 0x00,
|
||||
Construct = 0x20,
|
||||
}
|
||||
|
||||
#[repr(u8)]
|
||||
#[allow(unused)]
|
||||
#[expect(unused)]
|
||||
enum Class {
|
||||
Universal = 0x00,
|
||||
Application = 0x40,
|
||||
@@ -19,7 +18,7 @@ enum Class {
|
||||
}
|
||||
|
||||
#[repr(u8)]
|
||||
#[allow(unused)]
|
||||
#[expect(unused)]
|
||||
enum Tag {
|
||||
Mask = 0x1F,
|
||||
Boolean = 0x01,
|
||||
|
||||
@@ -139,7 +139,7 @@ macro_rules! try_write_optional {
|
||||
if let Some(ref val) = $val {
|
||||
// This is a workaround for clippy false positive because
|
||||
// of macro expansion.
|
||||
#[allow(clippy::redundant_closure_call)]
|
||||
#[expect(clippy::redundant_closure_call)]
|
||||
$f(val)?
|
||||
} else {
|
||||
return Ok(());
|
||||
|
||||
@@ -186,7 +186,7 @@ pub(crate) fn query_information(
|
||||
.unwrap_or_default();
|
||||
let name_index = match path.rfind('/') {
|
||||
// in fact, index only needs to be different for existing requests
|
||||
#[allow(clippy::arithmetic_side_effects)]
|
||||
#[expect(clippy::arithmetic_side_effects)]
|
||||
Some(index) => index + 1,
|
||||
None => 0,
|
||||
};
|
||||
@@ -312,6 +312,10 @@ pub(crate) fn query_volume_information(
|
||||
// blocks_available() may have different integer type on different platforms.
|
||||
// so we need to cast it to u32 uniformly. so if it is u32, it will emit 'useless conversion'
|
||||
// warning, i choose to mute it.
|
||||
#[expect(
|
||||
clippy::allow_attributes,
|
||||
reason = "we have to use allow as the useless_conversion isn't triggered on some platforms"
|
||||
)]
|
||||
#[allow(clippy::useless_conversion)]
|
||||
volume_serial_number: u32::try_from(statvfs.blocks_available()).unwrap(),
|
||||
supports_objects: Boolean::False,
|
||||
@@ -446,7 +450,7 @@ pub(crate) fn set_information(
|
||||
}
|
||||
|
||||
// in fact, it is time in secs which is very small
|
||||
#[allow(clippy::arithmetic_side_effects)]
|
||||
#[expect(clippy::arithmetic_side_effects)]
|
||||
pub(crate) fn transform_to_filetime(time_in_secs: i64) -> i64 {
|
||||
let mut time = time_in_secs * 10000000;
|
||||
time += 116444736000000000;
|
||||
@@ -491,7 +495,7 @@ pub(crate) fn make_query_dir_resp(
|
||||
))]),
|
||||
Some(file_full_path) => {
|
||||
// in fact, it represents file name, so it is not very large
|
||||
#[allow(clippy::arithmetic_side_effects)]
|
||||
#[expect(clippy::arithmetic_side_effects)]
|
||||
let file_last_slash = if let Some(index) = file_full_path.rfind('/') {
|
||||
index + 1
|
||||
} else {
|
||||
@@ -555,7 +559,7 @@ pub(crate) fn query_directory(
|
||||
let query_path = req_inner.path.replace('\\', "/");
|
||||
let len = query_path.len();
|
||||
// path ends with *, so its len > 0
|
||||
#[allow(clippy::arithmetic_side_effects)]
|
||||
#[expect(clippy::arithmetic_side_effects)]
|
||||
parent.push_str(&query_path[0..len - 1]);
|
||||
if let Ok(dirp) = Dir::open(
|
||||
parent.as_str(),
|
||||
@@ -643,7 +647,7 @@ fn make_create_drive_resp(
|
||||
Ok(vec![SvcMessage::from(res)])
|
||||
}
|
||||
// in fact, index only needs to be different, so it is ok
|
||||
#[allow(clippy::arithmetic_side_effects)]
|
||||
#[expect(clippy::arithmetic_side_effects)]
|
||||
pub(crate) fn create_drive(
|
||||
backend: &mut NixRdpdrBackend,
|
||||
req_inner: DeviceCreateRequest,
|
||||
|
||||
@@ -593,7 +593,7 @@ struct GeneralCapabilitySet {
|
||||
}
|
||||
|
||||
impl GeneralCapabilitySet {
|
||||
#[allow(clippy::manual_bits)]
|
||||
#[expect(clippy::manual_bits)]
|
||||
const SIZE: usize = size_of::<u32>() * 8 + size_of::<u16>() * 2;
|
||||
|
||||
fn encode(&self, dst: &mut WriteCursor<'_>) -> EncodeResult<()> {
|
||||
|
||||
@@ -243,7 +243,7 @@ impl RxBuffer {
|
||||
return;
|
||||
};
|
||||
|
||||
#[allow(clippy::arithmetic_side_effects)]
|
||||
#[expect(clippy::arithmetic_side_effects)]
|
||||
while self.idx < last.len() && filled < data.len() {
|
||||
data[filled] = last[self.idx];
|
||||
assert!(filled < usize::MAX);
|
||||
|
||||
@@ -49,7 +49,7 @@ impl Default for RdpServerBuilder<WantsAddr> {
|
||||
}
|
||||
|
||||
impl RdpServerBuilder<WantsAddr> {
|
||||
#[allow(clippy::unused_self)] // ensuring state transition from WantsAddr
|
||||
#[expect(clippy::unused_self)] // ensuring state transition from WantsAddr
|
||||
pub fn with_addr(self, addr: impl Into<SocketAddr>) -> RdpServerBuilder<WantsSecurity> {
|
||||
RdpServerBuilder {
|
||||
state: WantsSecurity { addr: addr.into() },
|
||||
|
||||
@@ -8,6 +8,10 @@ const MAX_FASTPATH_UPDATE_SIZE: usize = 16_374;
|
||||
|
||||
const FASTPATH_HEADER_SIZE: usize = 6;
|
||||
|
||||
#[expect(
|
||||
clippy::allow_attributes,
|
||||
reason = "Unfortunately, expect attribute doesn't work when above or after visibility::make attribute"
|
||||
)]
|
||||
#[allow(unreachable_pub)]
|
||||
#[cfg_attr(feature = "__bench", visibility::make(pub))]
|
||||
pub(crate) struct UpdateFragmenter {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user