Skip to content

Commit 6cad1e9

Browse files
committed
assign port_id_minimum to a value
1 parent 86182fe commit 6cad1e9

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

libcanard/canard.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ typedef uint16_t TransferCRC;
8181
#define CRC_INITIAL 0xFFFFU
8282
#define CRC_RESIDUE 0x0000U
8383
#define CRC_SIZE_BYTES 2U
84+
#define PORT_ID_MINIMUM 49152
8485

8586
#if (CANARD_CRC_TABLE != 0)
8687
static const uint16_t CRCTable[256] = {
@@ -1387,10 +1388,9 @@ int8_t canardRxSubscribe(struct CanardInstance* const ins,
13871388
int8_t out = -CANARD_ERROR_INVALID_ARGUMENT;
13881389
const size_t tk = (size_t) transfer_kind;
13891390

1390-
assert(port_id >= 49152 && port_id <= 65535);
1391-
if (port_id < 49152 || port_id > 65535)
1391+
if (port_id < PORT_ID_MINIMUM) // port_id can't be over 65535 because it exceeds type unsigned short maximum value.
13921392
{
1393-
fprintf(stderr, "Invalid port: %d. Port should be within 49152 to 65535\n", port_id);
1393+
(void) fprintf(stderr, "Invalid port: %d. Port should be within 49152 to 65535\n", port_id);
13941394
exit(EXIT_FAILURE);
13951395
}
13961396
if ((ins != NULL) && (out_subscription != NULL) && (tk < CANARD_NUM_TRANSFER_KINDS))

0 commit comments

Comments
 (0)