From 808a4de7dd1bfcbf2db55b4a2959ade6c2bfa881 Mon Sep 17 00:00:00 2001 From: G1gg1L3s Date: Sun, 21 Jul 2024 23:54:17 +0300 Subject: [PATCH] mavlink-bindgen: Allow absurd_extreme_comparisons As described in the comment, these lints are from the empty messages which have Self::ENCODED_LEN zero. For now, skip this lint in the check. The empty messages are actually forbidden by the mavlink schema [1]. But we generate a couple of empty cubepilot messages because the cubepilot.xml contains a couple of unclosed fields, like so: [1]: https://github.com/ArduPilot/pymavlink/blob/d251f7acbe9ce45175615fefdd4f094719ec1120/generator/mavschema.xsd#L305 ```xml Raw RC Data Herelink Telemetry ``` Python xml parser does a decend job at recovering from such cases. However, our current parser just ignores such fields. --- mavlink-bindgen/src/parser.rs | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/mavlink-bindgen/src/parser.rs b/mavlink-bindgen/src/parser.rs index a7a0da00cc..1ed238b815 100644 --- a/mavlink-bindgen/src/parser.rs +++ b/mavlink-bindgen/src/parser.rs @@ -502,14 +502,27 @@ impl MavMessage { fn emit_serialize_vars(&self) -> TokenStream { let ser_vars = self.fields.iter().map(|f| f.rust_writer()); + quote! { let mut __tmp = BytesMut::new(bytes); - assert!( - __tmp.remaining() >= Self::ENCODED_LEN, - "buffer is too small (need {} bytes, but got {})", - Self::ENCODED_LEN, - __tmp.remaining(), - ); + + // TODO: these lints are produced on a couple of cubepilot messages + // because they are generated as empty structs with no fields and + // therefore Self::ENCODED_LEN is 0. This itself is a bug because + // cubepilot.xml has unclosed tags in fields, which the parser has + // bad time handling. It should probably be fixed in both the parser + // and mavlink message definitions. However, until it's done, let's + // skip the lints. + #[allow(clippy::absurd_extreme_comparisons)] + #[allow(unused_comparisons)] + if __tmp.remaining() < Self::ENCODED_LEN { + panic!( + "buffer is too small (need {} bytes, but got {})", + Self::ENCODED_LEN, + __tmp.remaining(), + ) + } + #(#ser_vars)* if matches!(version, MavlinkVersion::V2) { let len = __tmp.len();