Skip to content

generator/CPP11: Define message::LENGTH and ::MIN_LENGTH as uint8_t#1182

Open
mr3screen wants to merge 1 commit into
ArduPilot:masterfrom
mr3screen:type-of-message_LENGTH
Open

generator/CPP11: Define message::LENGTH and ::MIN_LENGTH as uint8_t#1182
mr3screen wants to merge 1 commit into
ArduPilot:masterfrom
mr3screen:type-of-message_LENGTH

Conversation

@mr3screen

Copy link
Copy Markdown

The mavlink wire format only allows payloads up to 255 bytes and no message has LENGTH or MIN_LENGTH set to a valuer greater than 255. The mavlink_finalize_message*() family of functions to serialize a message expect the arguments uint8_t min_length and uint8_t length. A developers might be unsure why they're passing two size_t values to a function expecting uint8_ts and whether they need to manually check handle cases where truncation might occur.

With this change the types communicate no concern is needed.

Fixes #1181

I did not test this change.

Note: If you're concerned about future longer messages in the future where this change would create an overflow: C++11 added list initializations, which can be used to create compile errors, if the compile-time assigned value is larger than fits in the target type:

    static constexpr uint8_t LENGTH{256}; // this would not compile

The generator could be changed to use that instead of

    static constexpr uint8_t LENGTH = 256; 

The mavlink wire format only allows payloads up to 255 bytes and no
message has LENGTH or MIN_LENGTH set to a valuer greater than 255.  The
mavlink_finalize_message*() family of functions to serialize a message expect
the arguments `uint8_t min_length` and `uint8_t length`.  A developers  might
be unsure why they're passing two size_t values to a
function expecting uint8_ts and whether they need to manually check handle
cases where truncation might occur.

With this change the types communicate no concern is needed.

Fixes ArduPilot#1181
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(C++) mavlink::Message::MIN_LENGTH and LENGTH are of type size_t, but mavlink_finalize_message* expects uint8_t

1 participant