Skip to content

Commit

Permalink
move payload length check to top level decode function
Browse files Browse the repository at this point in the history
  • Loading branch information
tridge committed Feb 10, 2024
1 parent e8f8a8d commit f0916d2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
7 changes: 6 additions & 1 deletion templates/msg.c.em
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ uint32_t @(msg_underscored_name)_encode(@(msg_c_type)* msg, uint8_t* buffer
return true if the decode is invalid
*/
bool @(msg_underscored_name)_decode(const CanardRxTransfer* transfer, @(msg_c_type)* msg) {
#if CANARD_ENABLE_TAO_OPTION
if (transfer->tao && (transfer->payload_len > @(msg_define_name.upper())_MAX_SIZE)) {
return true; /* invalid payload length */
}
#endif
uint32_t bit_ofs = 0;
if (_@(msg_underscored_name)_decode(transfer, &bit_ofs, msg,
#if CANARD_ENABLE_TAO_OPTION
Expand All @@ -40,7 +45,7 @@ bool @(msg_underscored_name)_decode(const CanardRxTransfer* transfer, @(msg_c_ty
true
#endif
)) {
return true;
return true; /* invalid payload */
}

const uint32_t byte_len = (bit_ofs+7U)/8U;
Expand Down
3 changes: 0 additions & 3 deletions templates/msg.h.em
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,6 @@ bool _@(msg_underscored_name)_decode(const CanardRxTransfer* transfer, uint32_t*
@(ind)(void)bit_ofs;
@(ind)(void)msg;
@(ind)(void)tao;
@(ind)if (tao && (transfer->payload_len > @(msg_define_name.upper())_MAX_SIZE)) {
@(ind) return true; /* invalid payload length */
@(ind)}
@[ if msg_union]@
@(ind)@(union_msg_tag_uint_type_from_num_fields(len(msg_fields))) union_tag;
@(ind)canardDecodeScalar(transfer, *bit_ofs, @(union_msg_tag_bitlen_from_num_fields(len(msg_fields))), false, &union_tag);
Expand Down

0 comments on commit f0916d2

Please sign in to comment.