Skip to content

Commit

Permalink
SONAR
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-kirienko committed Aug 2, 2023
1 parent 81378f0 commit 48b287a
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions libudpard/udpard.c
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ static inline void rxFragmentDestroyTree(RxFragment* const self, const RxMemory
if (child != NULL)
{
UDPARD_ASSERT(child->base.up == &self->tree.base);
rxFragmentDestroyTree(child->this, memory);
rxFragmentDestroyTree(child->this, memory); // NOSONAR recursion
}
}
memFree(memory.fragment, sizeof(RxFragment), self); // self-destruct
Expand Down Expand Up @@ -943,7 +943,7 @@ static inline int8_t rxSlotFragmentSearch(void* const user_reference, const stru
{
UDPARD_ASSERT((user_reference != NULL) && (node != NULL));
const RxSlotUpdateContext* const ctx = (RxSlotUpdateContext*) user_reference;
RxFragment* const frag = ((RxFragmentTreeNode*) node)->this;
const RxFragment* const frag = ((const RxFragmentTreeNode*) node)->this;
UDPARD_ASSERT((ctx != NULL) && (frag != NULL));
int8_t out = 0;
if (ctx->frame_index > frag->frame_index)
Expand Down Expand Up @@ -995,7 +995,7 @@ static inline void rxSlotEjectFragment(RxFragment* const frag, RxSlotEjectContex
RxFragment* const child = ((RxFragmentTreeNode*) frag->tree.base.lr[0])->this;
UDPARD_ASSERT(child->frame_index < frag->frame_index);
UDPARD_ASSERT(child->tree.base.up == &frag->tree.base);
rxSlotEjectFragment(child, ctx);
rxSlotEjectFragment(child, ctx); // NOSONAR recursion
}
const size_t fragment_size = frag->base.view.size;
frag->base.next = NULL; // Default state; may be overwritten.
Expand All @@ -1020,7 +1020,7 @@ static inline void rxSlotEjectFragment(RxFragment* const frag, RxSlotEjectContex
RxFragment* const child = ((RxFragmentTreeNode*) frag->tree.base.lr[1])->this;
UDPARD_ASSERT(child->frame_index > frag->frame_index);
UDPARD_ASSERT(child->tree.base.up == &frag->tree.base);
rxSlotEjectFragment(child, ctx);
rxSlotEjectFragment(child, ctx); // NOSONAR recursion
}
// Drop the unneeded fragments and their handles after the sub-tree is fully traversed.
if (!retain)
Expand Down Expand Up @@ -1107,15 +1107,15 @@ static inline int_fast8_t rxSlotAccept(RxSlot* const self,
if ((self->eot_index != FRAME_INDEX_UNSET) && (self->eot_index != frame.index))
{
restart = true; // Inconsistent EOT flag, could be a node-ID conflict.
goto finish;
goto finish; // NOSONAR goto simplifies the control flow and is not prohibited by MISRA C:2012.
}
self->eot_index = frame.index;
}
UDPARD_ASSERT(frame.index <= self->max_index);
if (self->max_index > self->eot_index)
{
restart = true; // Frames past EOT found, discard the entire transfer because we don't trust it anymore.
goto finish;
goto finish; // NOSONAR goto simplifies the control flow and is not prohibited by MISRA C:2012.
}
// SECOND: Insert the fragment into the fragment tree. If it already exists, drop and free the duplicate.
UDPARD_ASSERT((self->max_index <= self->eot_index) && (self->accepted_frames <= self->eot_index));
Expand All @@ -1132,7 +1132,7 @@ static inline int_fast8_t rxSlotAccept(RxSlot* const self,
UDPARD_ASSERT(release);
result = -UDPARD_ERROR_MEMORY;
// No restart because there is hope that there will be enough memory when we receive a duplicate.
goto finish;
goto finish; // NOSONAR goto simplifies the control flow and is not prohibited by MISRA C:2012.
}
UDPARD_ASSERT(self->max_index <= self->eot_index);
if (update_ctx.accepted)
Expand Down Expand Up @@ -1363,7 +1363,9 @@ static inline bool rxSessionDeduplicate(UdpardInternalRxSession* const self,
memFreePayload(memory.payload, transfer->payload.origin);
rxFragmentDestroyList(transfer->payload.next, memory);
transfer->payload_size = 0;
transfer->payload = (struct UdpardFragment){.next = NULL, .view = {0}, .origin = {0}};
transfer->payload = (struct UdpardFragment){.next = NULL,
.view = {.size = 0, .data = NULL},
.origin = {.size = 0, .data = NULL}};
}
return accept;
}
Expand Down Expand Up @@ -1423,7 +1425,7 @@ static inline void rxSessionDestroyTree(UdpardInternalRxSession* const sel
if (child != NULL)
{
UDPARD_ASSERT(child->base.up == &self->base);
rxSessionDestroyTree(child, memory);
rxSessionDestroyTree(child, memory); // NOSONAR recursion
}
}
memFree(memory.session, sizeof(UdpardInternalRxSession), self);
Expand All @@ -1440,8 +1442,8 @@ typedef struct
static inline int8_t rxPortSessionSearch(void* const user_reference, const struct UdpardTreeNode* node)
{
UDPARD_ASSERT((user_reference != NULL) && (node != NULL));
const RxPortSessionSearchContext* const ctx = (const RxPortSessionSearchContext*) user_reference;
struct UdpardInternalRxSession* const session = (struct UdpardInternalRxSession*) node;
const RxPortSessionSearchContext* const ctx = (const RxPortSessionSearchContext*) user_reference;
const struct UdpardInternalRxSession* const session = (const struct UdpardInternalRxSession*) node;
UDPARD_ASSERT((ctx != NULL) && (session != NULL));
int8_t out = 0;
if (ctx->remote_node_id > session->remote_node_id)
Expand All @@ -1455,7 +1457,7 @@ static inline int8_t rxPortSessionSearch(void* const user_reference, const struc
return out;
}

static inline struct UdpardTreeNode* rxPortSessionFactory(void* const user_reference)
static inline struct UdpardTreeNode* rxPortSessionFactory(void* const user_reference) // NOSONAR non-const API
{
const RxPortSessionSearchContext* const ctx = (const RxPortSessionSearchContext*) user_reference;
UDPARD_ASSERT((ctx != NULL) && (ctx->remote_node_id <= UDPARD_NODE_ID_MAX));
Expand Down Expand Up @@ -1597,8 +1599,8 @@ int8_t udpardRxSubscriptionInit(struct UdpardRxSubscription* const self,
(void) subject_id;
(void) extent;
(void) memory;
(void) rxPortAcceptFrame;
(void) rxPortInit;
(void) rxPortFree;
(void) &rxPortAcceptFrame;
(void) &rxPortInit;
(void) &rxPortFree;
return 0;
}

0 comments on commit 48b287a

Please sign in to comment.