Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion libcanard/canard.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ typedef uint16_t TransferCRC;
#define CRC_INITIAL 0xFFFFU
#define CRC_RESIDUE 0x0000U
#define CRC_SIZE_BYTES 2U
#define PORT_ID_MINIMUM 49152
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's this for?


#if (CANARD_CRC_TABLE != 0)
static const uint16_t CRCTable[256] = {
Expand Down Expand Up @@ -1384,7 +1385,10 @@ int8_t canardRxSubscribe(struct CanardInstance* const ins,
{
int8_t out = -CANARD_ERROR_INVALID_ARGUMENT;
const size_t tk = (size_t) transfer_kind;
if ((ins != NULL) && (out_subscription != NULL) && (tk < CANARD_NUM_TRANSFER_KINDS))

if ((ins != NULL) && (out_subscription != NULL) && (tk < CANARD_NUM_TRANSFER_KINDS) &&
(((transfer_kind == CanardTransferKindMessage) && (port_id <= CANARD_SUBJECT_ID_MAX)) ||
(port_id <= CANARD_SERVICE_ID_MAX)))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please extract these into a port_id_ok variable to enhance readability, and remove the extra blank line.

{
// Reset to the initial state. This is absolutely critical because the new payload size limit may be larger
// than the old value; if there are any payload buffers allocated, we may overrun them because they are shorter
Expand Down
4 changes: 4 additions & 0 deletions tests/test_public_rx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,10 @@ TEST_CASE("RxSubscriptionErrors")
REQUIRE(-CANARD_ERROR_INVALID_ARGUMENT == canardRxSubscribe(&ins.getInstance(), kind.value, 0, 0, 0, &sub));
REQUIRE(-CANARD_ERROR_INVALID_ARGUMENT ==
canardRxSubscribe(&ins.getInstance(), CanardTransferKindMessage, 0, 0, 0, nullptr));
REQUIRE(-CANARD_ERROR_INVALID_ARGUMENT ==
canardRxSubscribe(&ins.getInstance(), CanardTransferKindMessage, 8192, 0, 0, &sub));
REQUIRE(-CANARD_ERROR_INVALID_ARGUMENT ==
canardRxSubscribe(&ins.getInstance(), CanardTransferKindResponse, 512, 0, 0, &sub));

REQUIRE(-CANARD_ERROR_INVALID_ARGUMENT == canardRxUnsubscribe(nullptr, CanardTransferKindMessage, 0));
REQUIRE(-CANARD_ERROR_INVALID_ARGUMENT == canardRxUnsubscribe(&ins.getInstance(), kind.value, 0));
Expand Down