From 2e3b11f6b8325080c160d38521b169b0bbb6b1c7 Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Fri, 15 Jul 2022 13:13:06 +0300 Subject: [PATCH] Follow-up for #197 -- fix minor issues discovered by Sonar (#198) * Fix issues discovered by Sonar * Update README.md --- README.md | 4 ++-- libcanard/canard.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 280ab91..943b0f9 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Compact Cyphal/CAN v1 in C +# Compact Cyphal/CAN in C [![Main Workflow](https://github.com/OpenCyphal/libcanard/actions/workflows/main.yml/badge.svg)](https://github.com/OpenCyphal/libcanard/actions/workflows/main.yml) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=libcanard&metric=alert_status)](https://sonarcloud.io/dashboard?id=libcanard) @@ -124,7 +124,7 @@ Use [Nunavut](https://github.com/OpenCyphal/nunavut) to automatically generate The CAN frames generated from the message transfer are now stored in the `queue`. We need to pick them out one by one and have them transmitted. Normally, the following fragment should be invoked periodically to unload the CAN frames from the -prioritized transmission queue into the CAN driver (or several, if redundant interfaces are used): +prioritized transmission queue (or several, if redundant interfaces are used) into the CAN driver: ```c for (const CanardTxQueueItem* ti = NULL; (ti = canardTxPeek(&queue)) != NULL;) // Peek at the top of the queue. diff --git a/libcanard/canard.c b/libcanard/canard.c index ba7e517..e3095f8 100644 --- a/libcanard/canard.c +++ b/libcanard/canard.c @@ -299,7 +299,7 @@ CANARD_PRIVATE TxItem* txAllocateQueueItem(CanardInstance* const ins, { CANARD_ASSERT(ins != NULL); CANARD_ASSERT(payload_size > 0U); - TxItem* const out = (TxItem*) ins->memory_allocate(ins, sizeof(TxItem) - CANARD_MTU_MAX + payload_size); + TxItem* const out = (TxItem*) ins->memory_allocate(ins, (sizeof(TxItem) - CANARD_MTU_MAX) + payload_size); if (out != NULL) { out->base.base.up = NULL; @@ -324,7 +324,7 @@ CANARD_PRIVATE int8_t txAVLPredicate(void* const user_reference, // NOSONAR Cav const CanardTreeNode* const node) { const CanardTxQueueItem* const target = (const CanardTxQueueItem*) user_reference; - const CanardTxQueueItem* const other = (const CanardTxQueueItem*) (void*) node; + const CanardTxQueueItem* const other = (const CanardTxQueueItem*) (const void*) node; CANARD_ASSERT((target != NULL) && (other != NULL)); return (target->frame.extended_can_id >= other->frame.extended_can_id) ? +1 : -1; } @@ -945,7 +945,7 @@ rxSubscriptionPredicateOnPortID(void* const user_reference, // NOSONAR Cavl API const CanardTreeNode* const node) { const CanardPortID sought = *((const CanardPortID*) user_reference); - const CanardPortID other = ((const CanardRxSubscription*) (void*) node)->port_id; + const CanardPortID other = ((const CanardRxSubscription*) (const void*) node)->port_id; static const int8_t NegPos[2] = {-1, +1}; // Clang-Tidy mistakenly identifies a narrowing cast to int8_t here, which is incorrect. return (sought == other) ? 0 : NegPos[sought > other]; // NOLINT no narrowing conversion is taking place here