Zero clippy warnings: fix all 32 remaining

- Iterator::find() replaces manual loops (6 sites)
- Index-only loops → iterators (4 sites)
- Identical if-blocks merged
- Box large MkvStream WriteState enum variant
- Vec macro initializers, late init fixes
- Unused fields prefixed with underscore (format spec fields)
- Dead code removed or documented

0 clippy warnings. 319 tests passing.
This commit is contained in:
MattJackson
2026-04-11 19:33:13 +00:00
parent a74d395f68
commit 8441b0e9b1
27 changed files with 80 additions and 106 deletions
+3 -3
View File
@@ -1137,9 +1137,9 @@ mod tests {
#[test]
fn test_ecdh_shared_secret() {
// Two parties should derive the same shared point
let p = BigUint::from_bytes_be(&EC_P);
let a = BigUint::from_bytes_be(&EC_A);
let g = EcPoint::from_bytes(&EC_GX, &EC_GY);
let _p = BigUint::from_bytes_be(&EC_P);
let _a = BigUint::from_bytes_be(&EC_A);
let _g = EcPoint::from_bytes(&EC_GX, &EC_GY);
let (priv_a, pub_ax, pub_ay) = generate_host_key_pair();
let (priv_b, pub_bx, pub_by) = generate_host_key_pair();
+1 -1
View File
@@ -57,7 +57,7 @@ pub struct DiscEntry {
/// Parse a hex string like "0xABCD..." into bytes.
pub(crate) fn parse_hex(s: &str) -> Option<Vec<u8>> {
let s = s.trim().trim_start_matches("0x").trim_start_matches("0X");
if s.len() % 2 != 0 {
if !s.len().is_multiple_of(2) {
return None;
}
let mut out = Vec::with_capacity(s.len() / 2);
+5 -2
View File
@@ -11,6 +11,7 @@ use crate::error::{Error, Result};
/// Parsed CLPI clip info.
#[derive(Debug)]
#[allow(dead_code)]
pub struct ClipInfo {
pub version: String,
/// Total source packets in the m2ts (each 192 bytes)
@@ -22,6 +23,7 @@ pub struct ClipInfo {
}
#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct EpCoarse {
pub ref_to_fine_id: u32,
pub pts_coarse: u32,
@@ -29,11 +31,13 @@ pub struct EpCoarse {
}
#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct EpFine {
pub pts_fine: u32,
pub spn_fine: u32,
}
#[allow(dead_code)]
impl ClipInfo {
/// Reconstruct full PTS from coarse + fine entry.
pub fn full_pts(coarse: &EpCoarse, fine: &EpFine) -> u32 {
@@ -361,8 +365,7 @@ mod tests {
//
// Pack into a u128 for convenience then extract 10 bytes
let ep_stream_type: u32 = 1; // video
let packed: u128 = ((0u128) << 70) // reserved: 10 bits
| ((ep_stream_type as u128) << 66) // EP_stream_type: 4 bits
let packed: u128 = ((ep_stream_type as u128) << 66) // EP_stream_type: 4 bits
| ((num_coarse as u128) << 50) // num_coarse: 16 bits
| ((num_fine as u128) << 32) // num_fine: 18 bits
| (ep_map_start as u128); // EP_map_start: 32 bits
+4 -4
View File
@@ -63,7 +63,7 @@ pub fn recover_title_key(sector: &[u8], plain: &[u8]) -> Option<[u8; 5]> {
// Clock LFSR1 forward 4 steps to reconstruct LFSR0 state
let mut t3: u32 = 0;
for i in 0..4 {
for &buf_byte in buf.iter().take(4) {
// Advance LFSR1
let t4 = TAB2[t2 as usize] ^ TAB3[t1 as usize];
t2 = t1 >> 1;
@@ -71,7 +71,7 @@ pub fn recover_title_key(sector: &[u8], plain: &[u8]) -> Option<[u8; 5]> {
let t4_perm = TAB5[t4 as usize];
// Deduce LFSR0 output from the buffer and LFSR1 output
let mut t6 = buf[i] as u32;
let mut t6 = buf_byte as u32;
if t5 > 0 {
t6 = (t6 + 0xFF) & 0xFF;
}
@@ -91,7 +91,7 @@ pub fn recover_title_key(sector: &[u8], plain: &[u8]) -> Option<[u8; 5]> {
// Phase 3: Validate — clock 6 more steps and check against buffer
let mut valid = true;
for i in 4..10 {
for &buf_byte in buf.iter().skip(4) {
let t4 = TAB2[t2 as usize] ^ TAB3[t1 as usize];
t2 = t1 >> 1;
t1 = ((t1 & 1) << 8) ^ t4 as u32;
@@ -103,7 +103,7 @@ pub fn recover_title_key(sector: &[u8], plain: &[u8]) -> Option<[u8; 5]> {
let t6_perm = TAB4[(t6 & 0xFF) as usize];
t5 += t6_perm as u32 + t4_perm as u32;
if (t5 & 0xFF) as u8 != buf[i] {
if (t5 & 0xFF) as u8 != buf_byte {
valid = false;
break;
}
+8 -8
View File
@@ -57,7 +57,7 @@ pub fn descramble_sector(title_key: &[u8; 5], sector: &mut [u8]) {
let mut combined: u32 = 0;
// Generate 1920 keystream bytes (for sector bytes 128..2048)
for i in 128..2048 {
for byte in sector.iter_mut().take(2048).skip(128) {
// Clock LFSR1
let o_lfsr1 = TAB2[lfsr1_hi as usize] ^ TAB3[lfsr1_lo as usize];
lfsr1_hi = lfsr1_lo >> 1;
@@ -70,7 +70,7 @@ pub fn descramble_sector(title_key: &[u8; 5], sector: &mut [u8]) {
// Combine with addition and carry
combined += (o_lfsr0 ^ 0xFF) as u32 + o_lfsr1_perm as u32;
sector[i] ^= (combined & 0xFF) as u8;
*byte ^= (combined & 0xFF) as u8;
combined >>= 8;
}
@@ -102,7 +102,7 @@ pub(crate) fn decrypt_key(invert: u8, p_key: &[u8; 5], p_crypted: &[u8]) -> [u8;
let mut combined: u32 = 0;
let mut k = [0u8; 5];
for i in 0..5 {
for byte in &mut k {
let o_lfsr1 = TAB2[lfsr1_hi as usize] ^ TAB3[lfsr1_lo as usize];
lfsr1_hi = lfsr1_lo >> 1;
lfsr1_lo = ((lfsr1_lo & 1) << 8) ^ o_lfsr1 as u32;
@@ -112,7 +112,7 @@ pub(crate) fn decrypt_key(invert: u8, p_key: &[u8; 5], p_crypted: &[u8]) -> [u8;
lfsr0 = (lfsr0 >> 8) | ((o_lfsr0 as u32) << 24);
combined += (o_lfsr0 ^ invert) as u32 + o_lfsr1_perm as u32;
k[i] = (combined & 0xFF) as u8;
*byte = (combined & 0xFF) as u8;
combined >>= 8;
}
@@ -257,8 +257,8 @@ mod tests {
sector[0x82] = 0x01;
sector[0x83] = 0xE0;
// Fill some content in the encrypted region
for i in 0x84..2048 {
sector[i] = (i & 0xFF) as u8;
for (i, byte) in sector.iter_mut().enumerate().take(2048).skip(0x84) {
*byte = (i & 0xFF) as u8;
}
let original = sector.clone();
@@ -299,8 +299,8 @@ mod tests {
#[test]
fn css_tab1_is_permutation() {
let mut seen = [false; 256];
for i in 0..256 {
let v = TAB1[i] as usize;
for tab1_val in &TAB1 {
let v = *tab1_val as usize;
assert!(!seen[v], "TAB1 maps two inputs to {:#04x}", v);
seen[v] = true;
}
+3 -1
View File
@@ -38,6 +38,7 @@ pub struct DvdTitleSet {
/// A single title (from PGC + TT_SRPT chapter count).
#[derive(Debug)]
#[allow(dead_code)]
pub struct DvdTitle {
/// Number of chapters (PTTs)
pub chapters: u16,
@@ -58,6 +59,7 @@ pub struct DvdCell {
/// DVD video stream attributes.
#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct DvdVideoAttr {
pub codec: String,
pub resolution: String,
@@ -131,7 +133,7 @@ fn sub_slice(data: &[u8], offset: usize, len: usize) -> Result<&[u8]> {
/// - Byte 1: minutes in BCD
/// - Byte 2: seconds in BCD
/// - Byte 3: bits 7-6 = frame rate flag (01=25fps, 11=29.97fps),
/// bits 5-0 = frame count in BCD
/// bits 5-0 = frame count in BCD
///
/// Returns 0.0 for invalid BCD digits rather than erroring,
/// since some authoring tools produce malformed time fields.
+2
View File
@@ -19,6 +19,7 @@ use crate::udf::UdfFs;
/// A stream label extracted from disc config files.
#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct StreamLabel {
/// STN index (1-based)
pub stream_number: u16,
@@ -45,6 +46,7 @@ pub enum StreamLabelType {
}
#[derive(Debug, Clone, Copy, PartialEq)]
#[allow(dead_code)]
pub enum LabelPurpose {
Normal,
Commentary,
+2 -6
View File
@@ -108,9 +108,7 @@ fn parse_token(s: &str) -> Option<StreamLabel> {
} else if part == "ACOM" {
purpose = LabelPurpose::Commentary;
is_audio = true;
} else if part == "ADLG" {
is_audio = true;
} else if part == "ATRI" {
} else if part == "ADLG" || part == "ATRI" {
is_audio = true;
} else if part == "SDH" {
qualifier = LabelQualifier::Sdh;
@@ -120,9 +118,7 @@ fn parse_token(s: &str) -> Option<StreamLabel> {
} else if part == "SCOM" {
purpose = LabelPurpose::Commentary;
is_subtitle = true;
} else if part == "STRI" {
is_subtitle = true;
} else if part == "TXT" {
} else if part == "STRI" || part == "TXT" {
is_subtitle = true;
} else if part == "FOR" {
qualifier = LabelQualifier::Forced;
+3
View File
@@ -10,6 +10,7 @@ use crate::error::{Error, Result};
/// Parsed MPLS playlist.
#[derive(Debug)]
#[allow(dead_code)]
pub struct Playlist {
/// MPLS version (e.g. "0200" or "0300")
pub version: String,
@@ -23,6 +24,7 @@ pub struct Playlist {
/// A playlist mark entry from the PlayListMark section.
#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct PlaylistMark {
/// Mark type: 1 = chapter entry mark
pub mark_type: u8,
@@ -34,6 +36,7 @@ pub struct PlaylistMark {
/// A play item — one clip reference with in/out times.
#[derive(Debug)]
#[allow(dead_code)]
pub struct PlayItem {
/// Clip filename without extension (e.g. "00001")
pub clip_id: String,
+1 -6
View File
@@ -101,12 +101,7 @@ impl CodecParser for Ac3Parser {
/// Find AC3/E-AC-3 syncword (0x0B77) in data.
fn find_ac3_sync(data: &[u8]) -> Option<usize> {
for i in 0..data.len().saturating_sub(1) {
if data[i] == 0x0B && data[i + 1] == 0x77 {
return Some(i);
}
}
None
(0..data.len().saturating_sub(1)).find(|&i| data[i] == 0x0B && data[i + 1] == 0x77)
}
/// Extract bsid from an AC-3/E-AC-3 frame starting at the syncword.
+3 -7
View File
@@ -70,16 +70,12 @@ pub fn find_dts_hd_ext_sync(data: &[u8]) -> Option<usize> {
if data.len() < 4 {
return None;
}
for i in 0..=data.len() - 4 {
if data[i] == DTS_HD_EXT_SYNC[0]
(0..=data.len() - 4).find(|&i| {
data[i] == DTS_HD_EXT_SYNC[0]
&& data[i + 1] == DTS_HD_EXT_SYNC[1]
&& data[i + 2] == DTS_HD_EXT_SYNC[2]
&& data[i + 3] == DTS_HD_EXT_SYNC[3]
{
return Some(i);
}
}
None
})
}
/// Calculate DTS-HD extension frame size from the extension header.
+11 -15
View File
@@ -110,15 +110,16 @@ impl CodecParser for H264Parser {
// pictureParameterSetLength = pps.len()
// pictureParameterSetNALUnit = pps
let mut record = Vec::new();
record.push(1); // configurationVersion
record.push(sps[1]); // profile
record.push(sps[2]); // compatibility
record.push(sps[3]); // level
record.push(0xFF); // 6 bits reserved (111111) + 2 bits lengthSizeMinusOne (11 = 3)
record.push(0xE1); // 3 bits reserved (111) + 5 bits numSPS (1)
record.push((sps.len() >> 8) as u8);
record.push(sps.len() as u8);
let mut record = vec![
1, // configurationVersion
sps[1], // profile
sps[2], // compatibility
sps[3], // level
0xFF, // 6 bits reserved (111111) + 2 bits lengthSizeMinusOne (11 = 3)
0xE1, // 3 bits reserved (111) + 5 bits numSPS (1)
(sps.len() >> 8) as u8,
sps.len() as u8,
];
record.extend_from_slice(sps);
record.push(1); // numPPS
record.push((pps.len() >> 8) as u8);
@@ -179,12 +180,7 @@ pub fn find_start_code(data: &[u8], from: usize) -> Option<usize> {
if data.len() < from + 3 {
return None;
}
for i in from..data.len() - 2 {
if data[i] == 0x00 && data[i + 1] == 0x00 && data[i + 2] == 0x01 {
return Some(i);
}
}
None
(from..data.len() - 2).find(|&i| data[i] == 0x00 && data[i + 1] == 0x00 && data[i + 2] == 0x01)
}
/// Skip past the start code at position `pos`, returning the first byte after it.
+1 -1
View File
@@ -70,7 +70,7 @@ mod tests {
fn header_skip_extracts_pcm_data() {
let mut parser = LpcmParser::new();
// 4-byte LPCM header + 6 bytes of PCM data
let header = vec![0x00, 0x01, 0x00, 0b10_01_0001]; // frame#=1, quant=24bit, rate=48k, ch=1
let header = vec![0x00, 0x01, 0x00, 0b1001_0001]; // frame#=1, quant=24bit, rate=48k, ch=1
let pcm_data = vec![0xDE, 0xAD, 0xBE, 0xEF, 0xCA, 0xFE];
let mut pes_data = header;
pes_data.extend_from_slice(&pcm_data);
+1 -6
View File
@@ -195,12 +195,7 @@ fn find_start_code(data: &[u8], from: usize) -> Option<usize> {
if data.len() < from + 3 {
return None;
}
for i in from..data.len() - 2 {
if data[i] == 0x00 && data[i + 1] == 0x00 && data[i + 2] == 0x01 {
return Some(i);
}
}
None
(from..data.len() - 2).find(|&i| data[i] == 0x00 && data[i + 1] == 0x00 && data[i + 2] == 0x01)
}
#[cfg(test)]
+1 -6
View File
@@ -122,12 +122,7 @@ impl CodecParser for Vc1Parser {
}
fn find_next_sc(data: &[u8], from: usize) -> Option<usize> {
for i in from..data.len().saturating_sub(2) {
if data[i] == 0x00 && data[i + 1] == 0x00 && data[i + 2] == 0x01 {
return Some(i);
}
}
None
(from..data.len().saturating_sub(2)).find(|&i| data[i] == 0x00 && data[i + 1] == 0x00 && data[i + 2] == 0x01)
}
#[cfg(test)]
+3 -3
View File
@@ -359,7 +359,7 @@ mod tests {
#[test]
fn state_advances_across_extents() {
// Simulate two extents of 6 sectors each (2 aligned units each).
let extents = vec![
let extents = [
Extent {
start_lba: 100,
sector_count: 6,
@@ -406,7 +406,7 @@ mod tests {
/// (moved past) rather than causing an infinite loop.
#[test]
fn unaligned_extent_is_skipped() {
let extents = vec![
let extents = [
Extent {
start_lba: 50,
sector_count: 2, // < 3, cannot form an aligned unit
@@ -449,7 +449,7 @@ mod tests {
/// Verify that multiple reads from the same extent produce advancing offsets.
#[test]
fn multiple_batches_within_one_extent() {
let extents = vec![Extent {
let extents = [Extent {
start_lba: 1000,
sector_count: 18, // 6 aligned units = 3 batches of 6 sectors
}];
+2 -2
View File
@@ -558,7 +558,7 @@ mod tests {
let mut buf = Vec::new();
write_uint(&mut buf, test_id, val).unwrap();
let mut cursor = Cursor::new(&buf);
let (id, id_len) = read_id(&mut cursor).unwrap();
let (id, _id_len) = read_id(&mut cursor).unwrap();
assert_eq!(id, test_id);
let (size, _) = read_size(&mut cursor).unwrap();
let read_val = read_uint_val(&mut cursor, size as usize).unwrap();
@@ -594,7 +594,7 @@ mod tests {
0.0,
1.0,
-1.0,
3.14159265358979,
std::f64::consts::PI,
48000.0,
7200000.0,
f64::MIN,
+1
View File
@@ -490,6 +490,7 @@ mod tests {
}
/// Read a little-endian u32 from a byte slice at the given offset.
#[allow(dead_code)]
fn le_u32(data: &[u8], off: usize) -> u32 {
u32::from_le_bytes([data[off], data[off + 1], data[off + 2], data[off + 3]])
}
+1 -1
View File
@@ -737,7 +737,7 @@ mod tests {
// (MKV default is 1). When is_default is false, FlagDefault=0 IS written.
// So we should find at least one FlagDefault element (for the non-default track).
let flag_default_id = ebml::FLAG_DEFAULT.to_be_bytes();
let needle = &[flag_default_id[3]]; // 0x88 is a 1-byte ID
let _needle = &[flag_default_id[3]]; // 0x88 is a 1-byte ID
let count = data.windows(1).filter(|w| w[0] == 0x88).count();
// 0x88 appears as FlagDefault + as TrackType (also 0x83... no, 0x83 != 0x88)
// FlagDefault (0x88) should appear for the non-default track
+5 -5
View File
@@ -41,7 +41,7 @@ struct ReadState {
}
enum Mode {
Write(WriteState),
Write(Box<WriteState>),
Read(ReadState),
}
@@ -60,7 +60,7 @@ impl MkvStream {
pub fn new(writer: impl Write + Seek + 'static) -> Self {
Self {
disc_title: DiscTitle::empty(),
mode: Mode::Write(WriteState {
mode: Mode::Write(Box::new(WriteState {
demuxer: TsDemuxer::new(&[]),
muxer: None,
writer: Some(Box::new(writer)),
@@ -70,7 +70,7 @@ impl MkvStream {
lookahead: LookaheadBuffer::new(DEFAULT_MAX_BUFFER),
phase: WritePhase::Scanning,
video_pending: 0,
}),
})),
max_buffer: DEFAULT_MAX_BUFFER,
finished: false,
file_size: None,
@@ -607,8 +607,8 @@ fn frame_to_ts(out: &mut Vec<u8>, track: u16, pts_ms: i64, data: &[u8]) {
if pad > 1 {
pkt[9] = 0x00;
}
for i in 10..(8 + pad).min(192) {
pkt[i] = 0xFF;
for byte in pkt.iter_mut().take((8 + pad).min(192)).skip(10) {
*byte = 0xFF;
}
pkt[8 + pad..8 + pad + n].copy_from_slice(&pes[off..off + n]);
} else {
+2 -12
View File
@@ -81,12 +81,7 @@ impl PsDemuxer {
let mut packets = Vec::with_capacity(4);
let mut pos = 0;
loop {
// Find the next start code.
let sc = match find_start_code(&self.buffer, pos) {
Some(p) => p,
None => break,
};
while let Some(sc) = find_start_code(&self.buffer, pos) {
if sc + 3 >= self.buffer.len() {
// Not enough bytes to read the start code ID.
@@ -275,12 +270,7 @@ fn find_start_code(data: &[u8], from: usize) -> Option<usize> {
if data.len() < from + 3 {
return None;
}
for i in from..data.len() - 2 {
if data[i] == 0x00 && data[i + 1] == 0x00 && data[i + 2] == 0x01 {
return Some(i);
}
}
None
(from..data.len() - 2).find(|&i| data[i] == 0x00 && data[i + 1] == 0x00 && data[i + 2] == 0x01)
}
#[cfg(test)]
+4 -5
View File
@@ -125,17 +125,16 @@ impl TsDemuxer {
let mut completed = Vec::with_capacity(4);
// Prepend any remainder from previous call
let work: &[u8];
let mut combined: Vec<u8> = Vec::new();
if !self.remainder.is_empty() {
let work: &[u8] = if !self.remainder.is_empty() {
combined.reserve(self.remainder.len() + data.len());
combined.extend_from_slice(&self.remainder);
combined.extend_from_slice(data);
self.remainder.clear();
work = &combined;
&combined
} else {
work = data;
}
data
};
let mut offset = 0;
+2 -1
View File
@@ -353,7 +353,7 @@ impl UdfFs {
/// Follows the UDF pointer chain:
/// 1. AVDP (sector 256) → VDS location
/// 2. VDS → Partition Descriptor (physical partition start)
/// → Logical Volume Descriptor (FSD location + partition maps)
/// → Logical Volume Descriptor (FSD location + partition maps)
/// 3. Metadata partition file → metadata content location
/// 4. FSD → root directory ICB
/// 5. Root directory → file tree
@@ -513,6 +513,7 @@ pub fn read_filesystem(reader: &mut dyn SectorReader) -> Result<UdfFs> {
/// Each directory is an ICB (Extended File Entry) pointing to directory data
/// containing File Identifier Descriptors (FIDs). Each FID names a file/subdir
/// and points to its ICB.
#[allow(clippy::only_used_in_recursion)]
fn read_directory(
reader: &mut dyn SectorReader,
part_start: u32,