Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust clippy172 v1 #9418

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rust/src/applayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl StreamSlice {
#[cfg(test)]
pub fn from_slice(slice: &[u8], flags: u8, offset: u64) -> Self {
Self {
input: slice.as_ptr() as *const u8,
input: slice.as_ptr(),
input_len: slice.len() as u32,
flags,
offset
Expand Down
4 changes: 2 additions & 2 deletions rust/src/detect/byte_math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,15 +432,15 @@ pub unsafe extern "C" fn ScByteMathParse(c_arg: *const c_char) -> *mut DetectByt
}
};
match parse_bytemath(arg) {
Ok((_, detect)) => return Box::into_raw(Box::new(detect)) as *mut DetectByteMathData,
Ok((_, detect)) => return Box::into_raw(Box::new(detect)),
Err(_) => return std::ptr::null_mut(),
}
}

#[no_mangle]
pub unsafe extern "C" fn ScByteMathFree(ptr: *mut DetectByteMathData) {
if !ptr.is_null() {
let _ = Box::from_raw(ptr as *mut DetectByteMathData);
let _ = Box::from_raw(ptr);
}
}

Expand Down
2 changes: 1 addition & 1 deletion rust/src/detect/iprep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub fn detect_parse_iprep(i: &str) -> IResult<&str, DetectIPRepData> {
let (i, name) = take_while(is_alphanumeric_or_slash)(i)?;
// copy as to have final zero
let namez = CString::new(name).unwrap();
let cat = unsafe { SRepCatGetByShortname(namez.as_ptr() as *const i8) };
let cat = unsafe { SRepCatGetByShortname(namez.as_ptr()) };
Copy link
Member

Choose a reason for hiding this comment

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

This gives errors on my arm builders:

   Compiling suricata v7.0.1-dev (/builds/inliniac/suricata-ci/suricata/rust)
error[E0308]: mismatched types
  --> src/detect/iprep.rs:87:46
   |
87 |     let cat = unsafe { SRepCatGetByShortname(namez.as_ptr()) };
   |                        --------------------- ^^^^^^^^^^^^^^ expected `*const i8`, found `*const u8`
   |                        |
   |                        arguments to this function are incorrect
   |
   = note: expected raw pointer `*const i8`
              found raw pointer `*const u8`
note: function defined here
  --> src/detect/iprep.rs:74:12
   |
74 |     pub fn SRepCatGetByShortname(name: *const i8) -> u8;
   |            ^^^^^^^^^^^^^^^^^^^^^
For more information about this error, try `rustc --explain E0308`.
error: could not compile `suricata` (lib) due to previous error


   Compiling suricata v7.0.1-dev (/builds/inliniac/suricata-ci/suricata/rust)
error[E0308]: mismatched types
  --> src/detect/iprep.rs:87:46
   |
87 |     let cat = unsafe { SRepCatGetByShortname(namez.as_ptr()) };
   |                        --------------------- ^^^^^^^^^^^^^^ expected `i8`, found `u8`
   |                        |
   |                        arguments to this function are incorrect
   |
   = note: expected raw pointer `*const i8`
              found raw pointer `*const u8`
note: function defined here
  --> src/detect/iprep.rs:74:12
   |
74 |     pub fn SRepCatGetByShortname(name: *const i8) -> u8;
   |            ^^^^^^^^^^^^^^^^^^^^^
For more information about this error, try `rustc --explain E0308`.
error: could not compile `suricata` due to previous error

Not sure why the 2 errors are different, perhaps rustc version differences.

Copy link
Member

Choose a reason for hiding this comment

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

IIRC C type char is unsigned in arm.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed

if cat == 0 {
return Err(Err::Error(make_error(i, ErrorKind::MapOpt)));
}
Expand Down
2 changes: 1 addition & 1 deletion rust/src/ffi/base64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub unsafe extern "C" fn Base64Encode(
if encoded.len() + 1 > *output_len as usize {
return Base64ReturnCode::SC_BASE64_OVERFLOW;
}
let output = std::slice::from_raw_parts_mut(&mut *(output as *mut u8), *output_len as usize);
let output = std::slice::from_raw_parts_mut(&mut *output, *output_len as usize);
output[0..encoded.len()].copy_from_slice(encoded.as_bytes());
output[encoded.len()] = 0;
*output_len = encoded.len() as c_ulong;
Expand Down
2 changes: 1 addition & 1 deletion rust/src/pgsql/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ pub fn pgsql_parse_startup_packet(i: &[u8]) -> IResult<&[u8], PgsqlFEMessage> {
let (i, b) = take(len - PGSQL_LENGTH_FIELD)(i)?;
let (_, message) =
match proto_major {
1 | 2 | 3 => {
1..=3 => {
let (b, proto_major) = be_u16(b)?;
let (b, proto_minor) = be_u16(b)?;
let (b, params) = pgsql_parse_startup_parameters(b)?;
Expand Down
7 changes: 4 additions & 3 deletions rust/src/rdp/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ pub enum Protocol {
// rdp-spec, section 2.2.1.1.1
bitflags! {
pub struct ProtocolFlags: u32 {
const PROTOCOL_RDP = Protocol::ProtocolRdp as u32;
//Protocol::ProtocolRdp is 0 as always supported
//and bitflags crate does not like zero-bit flags
const PROTOCOL_SSL = Protocol::ProtocolSsl as u32;
const PROTOCOL_HYBRID = Protocol::ProtocolHybrid as u32;
const PROTOCOL_RDSTLS = Protocol::ProtocolRdsTls as u32;
Expand Down Expand Up @@ -1089,7 +1090,7 @@ mod tests_negotiate_49350 {
cookie: None,
negotiation_request: Some(NegotiationRequest {
flags: NegotiationRequestFlags::empty(),
protocols: ProtocolFlags::PROTOCOL_RDP,
protocols: ProtocolFlags { bits: Protocol::ProtocolRdp as u32 },
}),
data: Vec::new(),
}),
Expand Down Expand Up @@ -1179,7 +1180,7 @@ mod tests_core_49350 {
),
client_dig_product_id: Some(String::from("")),
connection_hint: Some(ConnectionHint::ConnectionHintNotProvided),
server_selected_protocol: Some(ProtocolFlags::PROTOCOL_RDP),
server_selected_protocol: Some(ProtocolFlags { bits: Protocol::ProtocolRdp as u32 }),
desktop_physical_width: None,
desktop_physical_height: None,
desktop_orientation: None,
Expand Down
Loading