Skip to content

Commit 3d9e647

Browse files
committed
add bool port_id_ok
1 parent a48f9bb commit 3d9e647

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

libcanard/canard.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ typedef uint16_t TransferCRC;
7979
#define CRC_INITIAL 0xFFFFU
8080
#define CRC_RESIDUE 0x0000U
8181
#define CRC_SIZE_BYTES 2U
82-
#define PORT_ID_MINIMUM 49152
8382

8483
#if (CANARD_CRC_TABLE != 0)
8584
static const uint16_t CRCTable[256] = {
@@ -1383,12 +1382,11 @@ int8_t canardRxSubscribe(struct CanardInstance* const ins,
13831382
const CanardMicrosecond transfer_id_timeout_usec,
13841383
struct CanardRxSubscription* const out_subscription)
13851384
{
1386-
int8_t out = -CANARD_ERROR_INVALID_ARGUMENT;
1387-
const size_t tk = (size_t) transfer_kind;
1388-
1389-
if ((ins != NULL) && (out_subscription != NULL) && (tk < CANARD_NUM_TRANSFER_KINDS) &&
1390-
(((transfer_kind == CanardTransferKindMessage) && (port_id <= CANARD_SUBJECT_ID_MAX)) ||
1391-
(port_id <= CANARD_SERVICE_ID_MAX)))
1385+
int8_t out = -CANARD_ERROR_INVALID_ARGUMENT;
1386+
const size_t tk = (size_t) transfer_kind;
1387+
const bool port_id_ok = ((transfer_kind == CanardTransferKindMessage) && (port_id <= CANARD_SUBJECT_ID_MAX)) ||
1388+
(port_id <= CANARD_SERVICE_ID_MAX);
1389+
if ((ins != NULL) && (out_subscription != NULL) && (tk < CANARD_NUM_TRANSFER_KINDS) && port_id_ok)
13921390
{
13931391
// Reset to the initial state. This is absolutely critical because the new payload size limit may be larger
13941392
// than the old value; if there are any payload buffers allocated, we may overrun them because they are shorter

0 commit comments

Comments
 (0)