Skip to content

Commit

Permalink
fixed clippy issues,
Browse files Browse the repository at this point in the history
and allowed redundant field names
  • Loading branch information
george-cosma committed Aug 7, 2023
1 parent e989e86 commit 5f5fcf2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
10 changes: 6 additions & 4 deletions tbf-parser/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ pub fn parse_tbf_header(

// If there is nothing left in the header then this is just a
// padding "app" between two other apps.
if remaining.len() == 0 {
if remaining.is_empty() {
// Just padding.
Ok(types::TbfHeader::Padding(tbf_header_base))
} else {
Expand All @@ -145,7 +145,7 @@ pub fn parse_tbf_header(
let mut kernel_version: Option<types::TbfHeaderV2KernelVersion> = None;

// Iterate the remainder of the header looking for TLV entries.
while remaining.len() > 0 {
while !remaining.is_empty() {
// Get the T and L portions of the next header (if it is
// there).
let tlv_header: types::TbfTlv = remaining
Expand Down Expand Up @@ -217,8 +217,10 @@ pub fn parse_tbf_header(
}

// Convert and store each wfr.
for i in 0..number_regions {
wfr_pointer[i] = Some(
for (i, region) in
wfr_pointer.iter_mut().enumerate().take(number_regions)
{
*region = Some(
wfr_slice
.get(i * wfr_len..(i + 1) * wfr_len)
.ok_or(types::TbfParseError::NotEnoughFlash)?
Expand Down
34 changes: 16 additions & 18 deletions tbf-parser/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ impl<const L: usize> core::convert::TryFrom<&[u8]> for TbfHeaderV2Permissions<L>
let end = start + size_of::<TbfHeaderDriverPermission>();
if let Some(perm) = perms.get_mut(i) {
*perm = b
.get(start..end as usize)
.get(start..end)
.ok_or(TbfParseError::NotEnoughFlash)?
.try_into()?;
} else {
Expand Down Expand Up @@ -541,7 +541,7 @@ impl<const L: usize> core::convert::TryFrom<&[u8]> for TbfHeaderV2StoragePermiss
read_end = start + size_of::<u32>();
if let Some(read_id) = read_ids.get_mut(i) {
*read_id = u32::from_le_bytes(
b.get(start..read_end as usize)
b.get(start..read_end)
.ok_or(TbfParseError::NotEnoughFlash)?
.try_into()?,
);
Expand All @@ -564,7 +564,7 @@ impl<const L: usize> core::convert::TryFrom<&[u8]> for TbfHeaderV2StoragePermiss
let modify_end = start + size_of::<u32>();
if let Some(modify_id) = modify_ids.get_mut(i) {
*modify_id = u32::from_le_bytes(
b.get(start..modify_end as usize)
b.get(start..modify_end)
.ok_or(TbfParseError::NotEnoughFlash)?
.try_into()?,
);
Expand Down Expand Up @@ -681,6 +681,9 @@ pub struct TbfHeaderV2<'a> {
/// The kernel can also use this header to keep persistent state about
/// the application.
#[derive(Debug)]
// Clippy suggests we box TbfHeaderV2. We can't really do that, since
// we are runnning under no_std, and I don't think it's that big of a issue.
#[allow(clippy::large_enum_variant)]
pub enum TbfHeader<'a> {
TbfHeaderV2(TbfHeaderV2<'a>),
Padding(TbfHeaderV2Base),
Expand Down Expand Up @@ -900,10 +903,9 @@ impl TbfHeader<'_> {
/// Returns `None` if a `read_ids` is not included.
pub fn get_storage_read_ids(&self) -> Option<(usize, [u32; NUM_STORAGE_PERMISSIONS])> {
match self {
TbfHeader::TbfHeaderV2(hd) => match hd.storage_permissions {
Some(permissions) => Some((permissions.read_length.into(), permissions.read_ids)),
_ => None,
},
TbfHeader::TbfHeaderV2(hd) => hd
.storage_permissions
.map(|permissions| (permissions.read_length.into(), permissions.read_ids)),
_ => None,
}
}
Expand All @@ -912,12 +914,9 @@ impl TbfHeader<'_> {
/// Returns `None` if a `access_ids` is not included.
pub fn get_storage_modify_ids(&self) -> Option<(usize, [u32; NUM_STORAGE_PERMISSIONS])> {
match self {
TbfHeader::TbfHeaderV2(hd) => match hd.storage_permissions {
Some(permissions) => {
Some((permissions.modify_length.into(), permissions.modify_ids))
}
_ => None,
},
TbfHeader::TbfHeaderV2(hd) => hd
.storage_permissions
.map(|permissions| (permissions.modify_length.into(), permissions.modify_ids)),
_ => None,
}
}
Expand All @@ -926,10 +925,9 @@ impl TbfHeader<'_> {
/// Returns `None` if the kernel compatibility header is not included.
pub fn get_kernel_version(&self) -> Option<(u16, u16)> {
match self {
TbfHeader::TbfHeaderV2(hd) => match hd.kernel_version {
Some(kernel_version) => Some((kernel_version.major, kernel_version.minor)),
_ => None,
},
TbfHeader::TbfHeaderV2(hd) => hd
.kernel_version
.map(|kernel_version| (kernel_version.major, kernel_version.minor)),
_ => None,
}
}
Expand All @@ -941,7 +939,7 @@ impl TbfHeader<'_> {
match self {
TbfHeader::TbfHeaderV2(hd) => hd
.program
.map_or(hd.base.total_size as u32, |p| p.binary_end_offset),
.map_or(hd.base.total_size, |p| p.binary_end_offset),
_ => 0,
}
}
Expand Down
2 changes: 1 addition & 1 deletion tools/run_clippy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ if ! rustup component list | grep 'clippy.*(installed)' -q; then
fi

# TODO: What arguments do we want to pass to clippy?
CLIPPY_ARGS="-D warnings"
CLIPPY_ARGS="-D warnings -A clippy::redundant_field_names"

cargo clippy -- $CLIPPY_ARGS

0 comments on commit 5f5fcf2

Please sign in to comment.