Skip to content

Commit 4ec5685

Browse files
committed
fix the logic part
1 parent 6cad1e9 commit 4ec5685

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

libcanard/canard.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,12 +1388,9 @@ int8_t canardRxSubscribe(struct CanardInstance* const ins,
13881388
int8_t out = -CANARD_ERROR_INVALID_ARGUMENT;
13891389
const size_t tk = (size_t) transfer_kind;
13901390

1391-
if (port_id < PORT_ID_MINIMUM) // port_id can't be over 65535 because it exceeds type unsigned short maximum value.
1392-
{
1393-
(void) fprintf(stderr, "Invalid port: %d. Port should be within 49152 to 65535\n", port_id);
1394-
exit(EXIT_FAILURE);
1395-
}
1396-
if ((ins != NULL) && (out_subscription != NULL) && (tk < CANARD_NUM_TRANSFER_KINDS))
1391+
if ((ins != NULL) && (out_subscription != NULL) && (tk < CANARD_NUM_TRANSFER_KINDS) &&
1392+
((transfer_kind == CanardTransferKindMessage && port_id <= CANARD_SUBJECT_ID_MAX) ||
1393+
(port_id <= CANARD_SERVICE_ID_MAX)))
13971394
{
13981395
// Reset to the initial state. This is absolutely critical because the new payload size limit may be larger
13991396
// than the old value; if there are any payload buffers allocated, we may overrun them because they are shorter

0 commit comments

Comments
 (0)