From: Jason Ish Date: Wed, 5 Oct 2022 15:07:07 +0000 (-0600) Subject: rust: fix clippy lints for clippy::unnecessary_cast X-Git-Tag: suricata-7.0.0-beta1~31 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=04f0ee015179587f40225b29910539a600e838e0;p=thirdparty%2Fsuricata.git rust: fix clippy lints for clippy::unnecessary_cast --- diff --git a/rust/src/dcerpc/dcerpc.rs b/rust/src/dcerpc/dcerpc.rs index 5f1a0cc49e..93ff511621 100644 --- a/rust/src/dcerpc/dcerpc.rs +++ b/rust/src/dcerpc/dcerpc.rs @@ -602,7 +602,7 @@ impl DCERPCState { } d = &d[1..]; } - Err(Err::Incomplete(Needed::new(2 as usize - d.len()))) + Err(Err::Incomplete(Needed::new(2_usize - d.len()))) } /// Makes a call to the nom parser for parsing DCERPC Header. diff --git a/rust/src/dns/dns.rs b/rust/src/dns/dns.rs index 309349f5c3..0a065b130e 100644 --- a/rust/src/dns/dns.rs +++ b/rust/src/dns/dns.rs @@ -507,7 +507,7 @@ impl DNSState { let mut consumed = 0; while !cur_i.is_empty() { if cur_i.len() == 1 { - return AppLayerResult::incomplete(consumed as u32, 2 as u32); + return AppLayerResult::incomplete(consumed as u32, 2_u32); } let size = match be_u16(cur_i) as IResult<&[u8],u16> { Ok((_, len)) => len, @@ -556,7 +556,7 @@ impl DNSState { let mut consumed = 0; while !cur_i.is_empty() { if cur_i.len() == 1 { - return AppLayerResult::incomplete(consumed as u32, 2 as u32); + return AppLayerResult::incomplete(consumed as u32, 2_u32); } let size = match be_u16(cur_i) as IResult<&[u8],u16> { Ok((_, len)) => len, diff --git a/rust/src/filetracker.rs b/rust/src/filetracker.rs index 0d4fc394d5..7ddcda8322 100644 --- a/rust/src/filetracker.rs +++ b/rust/src/filetracker.rs @@ -165,7 +165,7 @@ impl FileTransferTracker { /// If gap_size > 0 'data' should not be used. /// return how much we consumed of data pub fn update(&mut self, files: &mut FileContainer, flags: u16, data: &[u8], gap_size: u32) -> u32 { - let mut consumed = 0 as usize; + let mut consumed = 0_usize; let is_gap = gap_size > 0; if is_gap || gap_size > 0 { SCLogDebug!("is_gap {} size {} ooo? {}", is_gap, gap_size, self.chunk_is_ooo); diff --git a/rust/src/http2/detect.rs b/rust/src/http2/detect.rs index 9c233cd4dc..515c9f471e 100644 --- a/rust/src/http2/detect.rs +++ b/rust/src/http2/detect.rs @@ -127,7 +127,7 @@ pub unsafe extern "C" fn rs_http2_parse_errorcode( fn http2_tx_get_next_priority( tx: &mut HTTP2Transaction, direction: Direction, nb: u32, ) -> std::os::raw::c_int { - let mut pos = 0 as u32; + let mut pos = 0_u32; if direction == Direction::ToServer { for i in 0..tx.frames_ts.len() { match &tx.frames_ts[i].data { @@ -187,7 +187,7 @@ pub unsafe extern "C" fn rs_http2_tx_get_next_priority( fn http2_tx_get_next_window( tx: &mut HTTP2Transaction, direction: Direction, nb: u32, ) -> std::os::raw::c_int { - let mut pos = 0 as u32; + let mut pos = 0_u32; if direction == Direction::ToServer { for i in 0..tx.frames_ts.len() { match tx.frames_ts[i].data { @@ -369,7 +369,7 @@ pub unsafe extern "C" fn rs_http2_detect_sizeupdatectx_match( pub unsafe extern "C" fn rs_http2_tx_get_header_name( tx: &mut HTTP2Transaction, direction: u8, nb: u32, buffer: *mut *const u8, buffer_len: *mut u32, ) -> u8 { - let mut pos = 0 as u32; + let mut pos = 0_u32; match direction.into() { Direction::ToServer => { for i in 0..tx.frames_ts.len() { @@ -810,7 +810,7 @@ pub unsafe extern "C" fn rs_http2_tx_get_headers_raw( pub unsafe extern "C" fn rs_http2_tx_get_header( tx: &mut HTTP2Transaction, direction: u8, nb: u32, buffer: *mut *const u8, buffer_len: *mut u32, ) -> u8 { - let mut pos = 0 as u32; + let mut pos = 0_u32; match direction.into() { Direction::ToServer => { for i in 0..tx.frames_ts.len() { diff --git a/rust/src/http2/http2.rs b/rust/src/http2/http2.rs index a8d9fbfb42..404081c94c 100644 --- a/rust/src/http2/http2.rs +++ b/rust/src/http2/http2.rs @@ -1014,7 +1014,7 @@ impl HTTP2State { self.progress = HTTP2ConnectionState::Http2StateMagicDone; } else { //still more buffer - return AppLayerResult::incomplete(0 as u32, HTTP2_MAGIC_LEN as u32); + return AppLayerResult::incomplete(0_u32, HTTP2_MAGIC_LEN as u32); } } //first consume frame bytes diff --git a/rust/src/nfs/nfs3.rs b/rust/src/nfs/nfs3.rs index 752ed7cde7..541b647078 100644 --- a/rust/src/nfs/nfs3.rs +++ b/rust/src/nfs/nfs3.rs @@ -233,7 +233,7 @@ impl NFSState { // cut off final eof field let d = if rd.data.len() >= 4 { - &rd.data[..rd.data.len()-4 as usize] + &rd.data[..rd.data.len()-4_usize] } else { rd.data }; diff --git a/rust/src/nfs/nfs4_records.rs b/rust/src/nfs/nfs4_records.rs index 9bbc91db52..e06fb51d5d 100644 --- a/rust/src/nfs/nfs4_records.rs +++ b/rust/src/nfs/nfs4_records.rs @@ -1646,7 +1646,7 @@ mod tests { let (r, attr) = nfs4_parse_attrbits(&buf[4..]).unwrap(); assert_eq!(r.len(), 0); // assert_eq!(attr.attr_mask, 35618163785728); - assert_eq!(attr.attr_mask, ((0x00002065 as u64) << 32 | 0 as u64)); + assert_eq!(attr.attr_mask, (0x00002065_u64 << 32 | 0_u64)); } #[test] fn test_nfs4_response_compound() { diff --git a/rust/src/smb/dcerpc.rs b/rust/src/smb/dcerpc.rs index 1741e6a0e3..25fec7d12a 100644 --- a/rust/src/smb/dcerpc.rs +++ b/rust/src/smb/dcerpc.rs @@ -459,7 +459,7 @@ pub fn smb_read_dcerpc_record<'b>(state: &mut SMBState, SCLogDebug!("lets first see if we have prior data"); // msg_id 0 as this data crosses cmd/reply pairs let ehdr = SMBHashKeyHdrGuid::new(SMBCommonHdr::new(SMBHDR_TYPE_TRANS_FRAG, - hdr.ssn_id as u64, hdr.tree_id as u32, 0 as u64), guid.to_vec()); + hdr.ssn_id as u64, hdr.tree_id as u32, 0_u64), guid.to_vec()); let mut prevdata = match state.ssnguid2vec_map.remove(&ehdr) { Some(s) => s, None => Vec::new(), diff --git a/rust/src/smb/smb.rs b/rust/src/smb/smb.rs index ddb2bb3a8f..dfa066d474 100644 --- a/rust/src/smb/smb.rs +++ b/rust/src/smb/smb.rs @@ -1193,7 +1193,7 @@ impl SMBState { fn add_nbss_ts_frames(&mut self, flow: *const Flow, stream_slice: &StreamSlice, input: &[u8], nbss_len: i64) -> (Option, Option, Option) { let nbss_pdu = Frame::new(flow, stream_slice, input, nbss_len + 4, SMBFrameType::NBSSPdu as u8); SCLogDebug!("NBSS PDU frame {:?}", nbss_pdu); - let nbss_hdr_frame = Frame::new(flow, stream_slice, input, 4 as i64, SMBFrameType::NBSSHdr as u8); + let nbss_hdr_frame = Frame::new(flow, stream_slice, input, 4_i64, SMBFrameType::NBSSHdr as u8); SCLogDebug!("NBSS HDR frame {:?}", nbss_hdr_frame); let nbss_data_frame = Frame::new(flow, stream_slice, &input[4..], nbss_len, SMBFrameType::NBSSData as u8); SCLogDebug!("NBSS DATA frame {:?}", nbss_data_frame); @@ -1206,7 +1206,7 @@ impl SMBState { smb_pdu } fn add_smb1_ts_hdr_data_frames(&mut self, flow: *const Flow, stream_slice: &StreamSlice, input: &[u8], nbss_len: i64) { - let _smb1_hdr = Frame::new(flow, stream_slice, input, 32 as i64, SMBFrameType::SMB1Hdr as u8); + let _smb1_hdr = Frame::new(flow, stream_slice, input, 32_i64, SMBFrameType::SMB1Hdr as u8); SCLogDebug!("SMBv1 HDR frame {:?}", _smb1_hdr); if input.len() > 32 { let _smb1_data = Frame::new(flow, stream_slice, &input[32..], (nbss_len - 32) as i64, SMBFrameType::SMB1Data as u8); @@ -1234,7 +1234,7 @@ impl SMBState { smb_pdu } fn add_smb3_ts_hdr_data_frames(&mut self, flow: *const Flow, stream_slice: &StreamSlice, input: &[u8], nbss_len: i64) { - let _smb3_hdr = Frame::new(flow, stream_slice, input, 52 as i64, SMBFrameType::SMB3Hdr as u8); + let _smb3_hdr = Frame::new(flow, stream_slice, input, 52_i64, SMBFrameType::SMB3Hdr as u8); SCLogDebug!("SMBv3 HDR frame {:?}", _smb3_hdr); if input.len() > 52 { let _smb3_data = Frame::new(flow, stream_slice, &input[52..], (nbss_len - 52) as i64, SMBFrameType::SMB3Data as u8); @@ -1537,7 +1537,7 @@ impl SMBState { fn add_nbss_tc_frames(&mut self, flow: *const Flow, stream_slice: &StreamSlice, input: &[u8], nbss_len: i64) -> (Option, Option, Option) { let nbss_pdu = Frame::new(flow, stream_slice, input, nbss_len + 4, SMBFrameType::NBSSPdu as u8); SCLogDebug!("NBSS PDU frame {:?}", nbss_pdu); - let nbss_hdr_frame = Frame::new(flow, stream_slice, input, 4 as i64, SMBFrameType::NBSSHdr as u8); + let nbss_hdr_frame = Frame::new(flow, stream_slice, input, 4_i64, SMBFrameType::NBSSHdr as u8); SCLogDebug!("NBSS HDR frame {:?}", nbss_hdr_frame); let nbss_data_frame = Frame::new(flow, stream_slice, &input[4..], nbss_len, SMBFrameType::NBSSData as u8); SCLogDebug!("NBSS DATA frame {:?}", nbss_data_frame); @@ -1578,7 +1578,7 @@ impl SMBState { SCLogDebug!("SMBv3 PDU frame {:?}", _smb_pdu); } fn add_smb3_tc_hdr_data_frames(&mut self, flow: *const Flow, stream_slice: &StreamSlice, input: &[u8], nbss_len: i64) { - let _smb3_hdr = Frame::new(flow, stream_slice, input, 52 as i64, SMBFrameType::SMB3Hdr as u8); + let _smb3_hdr = Frame::new(flow, stream_slice, input, 52_i64, SMBFrameType::SMB3Hdr as u8); SCLogDebug!("SMBv3 HDR frame {:?}", _smb3_hdr); if input.len() > 52 { let _smb3_data = Frame::new(flow, stream_slice, &input[52..], (nbss_len - 52) as i64, SMBFrameType::SMB3Data as u8); diff --git a/rust/src/smb/smb2_records.rs b/rust/src/smb/smb2_records.rs index 4baa61e335..a252a32447 100644 --- a/rust/src/smb/smb2_records.rs +++ b/rust/src/smb/smb2_records.rs @@ -599,7 +599,7 @@ pub fn parse_smb2_response_record(i: &[u8]) -> IResult<&[u8], Smb2Record> { fn smb_basic_search(d: &[u8]) -> usize { let needle = b"SMB"; - let mut r = 0 as usize; + let mut r = 0_usize; // this could be replaced by aho-corasick let iter = d.windows(needle.len()); for window in iter { @@ -626,5 +626,5 @@ pub fn search_smb_record<'a>(i: &'a [u8]) -> IResult<&'a [u8], &'a [u8]> { } d = &d[index + 3..]; } - Err(Err::Incomplete(Needed::new(4 as usize - d.len()))) + Err(Err::Incomplete(Needed::new(4_usize - d.len()))) } diff --git a/rust/src/ssh/ssh.rs b/rust/src/ssh/ssh.rs index 95564a0a0b..1f261b1dcd 100644 --- a/rust/src/ssh/ssh.rs +++ b/rust/src/ssh/ssh.rs @@ -261,7 +261,7 @@ impl SSHState { return r; } Err(Err::Incomplete(_)) => { - return AppLayerResult::incomplete(0 as u32, (input.len() + 1) as u32); + return AppLayerResult::incomplete(0_u32, (input.len() + 1) as u32); } Err(_e) => { SCLogDebug!("SSH invalid banner {}", _e); @@ -301,7 +301,7 @@ impl SSHState { Err(Err::Incomplete(_)) => { if input.len() < SSH_MAX_BANNER_LEN { //0 consumed, needs at least one more byte - return AppLayerResult::incomplete(0 as u32, (input.len() + 1) as u32); + return AppLayerResult::incomplete(0_u32, (input.len() + 1) as u32); } else { SCLogDebug!( "SSH banner too long {} vs {} and waiting for eol", diff --git a/rust/src/telnet/telnet.rs b/rust/src/telnet/telnet.rs index b9102cc682..86e3458746 100644 --- a/rust/src/telnet/telnet.rs +++ b/rust/src/telnet/telnet.rs @@ -176,7 +176,7 @@ impl TelnetState { flow, stream_slice, start, - -1 as i64, + -1_i64, TelnetFrameType::Pdu as u8, ); } @@ -187,7 +187,7 @@ impl TelnetState { flow, stream_slice, start, - -1 as i64, + -1_i64, TelnetFrameType::Ctl as u8, ) } else { @@ -195,7 +195,7 @@ impl TelnetState { flow, stream_slice, start, - -1 as i64, + -1_i64, TelnetFrameType::Data as u8, ) // app-layer-frame-documentation tag end: parse_request @@ -280,14 +280,14 @@ impl TelnetState { let mut start = input; while !start.is_empty() { if self.response_frame.is_none() { - self.response_frame = Frame::new(flow, stream_slice, start, -1 as i64, TelnetFrameType::Pdu as u8); + self.response_frame = Frame::new(flow, stream_slice, start, -1_i64, TelnetFrameType::Pdu as u8); } if self.response_specific_frame.is_none() { if let Ok((_, is_ctl)) = parser::peek_message_is_ctl(start) { self.response_specific_frame = if is_ctl { - Frame::new(flow, stream_slice, start, -1 as i64, TelnetFrameType::Ctl as u8) + Frame::new(flow, stream_slice, start, -1_i64, TelnetFrameType::Ctl as u8) } else { - Frame::new(flow, stream_slice, start, -1 as i64, TelnetFrameType::Data as u8) + Frame::new(flow, stream_slice, start, -1_i64, TelnetFrameType::Data as u8) }; } }