Skip to content

Commit

Permalink
mavlink-bindgen: Allow absurd_extreme_comparisons
Browse files Browse the repository at this point in the history
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

    <message id="50001" name="CUBEPILOT_RAW_RC">
      <description>Raw RC Data</description>
      <field type="uint8_t[32]" name="rc_raw"/>
    </message>

    <message id="50003" name="HERELINK_TELEM">
      <description>Herelink Telemetry</description>
      <field type="uint8_t" name="rssi"/>
      <field type="int16_t" name="snr"/>
      <field type="uint32_t" name="rf_freq"/>
      <field type="uint32_t" name="link_bw"/>
      <field type="uint32_t" name="link_rate"/>
      <field type="int16_t" name="cpu_temp"/>
      <field type="int16_t" name="board_temp"/>
    </message>
```

Python xml parser does a decend job at recovering from such cases.
However, our current parser just ignores such fields.
  • Loading branch information
G1gg1L3s committed Jul 21, 2024
1 parent 2813c89 commit 808a4de
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions mavlink-bindgen/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 808a4de

Please sign in to comment.