Skip to content

Commit

Permalink
check decode return in C++ wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
tridge committed Feb 10, 2024
1 parent 3813bd7 commit 7ac7d17
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion canard/service_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ class Client : public HandlerList, public Sender {
/// @param transfer transfer object of the request
void handle_message(const CanardRxTransfer& transfer) override {
rsptype msg {};
rsptype::cxx_iface::rsp_decode(&transfer, &msg);
if (!rsptype::cxx_iface::rsp_decode(&transfer, &msg)) {
return;
}

// scan through the list of entries for corresponding server node id and transfer id
Client<rsptype>* entry = branch_head[index];
Expand Down
4 changes: 3 additions & 1 deletion canard/service_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ class Server : public HandlerList {
/// @param transfer transfer object of the request
void handle_message(const CanardRxTransfer& transfer) override {
reqtype msg {};
reqtype::cxx_iface::req_decode(&transfer, &msg);
if (!reqtype::cxx_iface::req_decode(&transfer, &msg)) {
return;
}
transfer_id = transfer.transfer_id;
// call the registered callback
cb(transfer, msg);
Expand Down
4 changes: 3 additions & 1 deletion canard/subscriber.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ class Subscriber : public HandlerList {
/// @param transfer transfer object
void handle_message(const CanardRxTransfer& transfer) override {
msgtype msg {};
msgtype::cxx_iface::decode(&transfer, &msg);
if (!msgtype::cxx_iface::decode(&transfer, &msg)) {
return;
}
// call all registered callbacks in one go
Subscriber<msgtype>* entry = branch_head[index];
while (entry != nullptr) {
Expand Down

0 comments on commit 7ac7d17

Please sign in to comment.