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 authored and bugobliterator committed Feb 10, 2024
1 parent e03112f commit 0ae477b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
5 changes: 4 additions & 1 deletion canard/service_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ 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)) {
// invalid decode
return;
}

// scan through the list of entries for corresponding server node id and transfer id
Client<rsptype>* entry = branch_head[index];
Expand Down
5 changes: 4 additions & 1 deletion canard/service_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ 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)) {
// invalid decode
return;
}
transfer_id = transfer.transfer_id;
// call the registered callback
cb(transfer, msg);
Expand Down
5 changes: 4 additions & 1 deletion canard/subscriber.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ 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)) {
// invalid decode
return;
}
// call all registered callbacks in one go
Subscriber<msgtype>* entry = branch_head[index];
while (entry != nullptr) {
Expand Down

0 comments on commit 0ae477b

Please sign in to comment.