Skip to content

Commit 987ba8f

Browse files
committed
fix the logic part
1 parent 6cad1e9 commit 987ba8f

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

libcanard/canard.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,11 +1388,15 @@ 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.
1391+
if (tk == 0 && port_id > CANARD_SUBJECT_ID_MAX)
13921392
{
1393-
(void) fprintf(stderr, "Invalid port: %d. Port should be within 49152 to 65535\n", port_id);
1394-
exit(EXIT_FAILURE);
1393+
return out;
13951394
}
1395+
if (port_id > CANARD_SERVICE_ID_MAX)
1396+
{
1397+
return out;
1398+
}
1399+
13961400
if ((ins != NULL) && (out_subscription != NULL) && (tk < CANARD_NUM_TRANSFER_KINDS))
13971401
{
13981402
// Reset to the initial state. This is absolutely critical because the new payload size limit may be larger

0 commit comments

Comments
 (0)