From 142590dce3edb85898eeefa65e704d810980edb6 Mon Sep 17 00:00:00 2001 From: Sergei Shirokov Date: Thu, 28 Nov 2024 15:30:05 +0200 Subject: [PATCH] udpardTxPop now accepts mutable item #sonar --- libudpard/udpard.c | 9 ++------- libudpard/udpard.h | 2 +- tests/src/test_e2e.cpp | 4 ++-- tests/src/test_intrusive_tx.c | 4 ++-- tests/src/test_tx.cpp | 6 +++--- 5 files changed, 10 insertions(+), 15 deletions(-) diff --git a/libudpard/udpard.c b/libudpard/udpard.c index 80e0bbb..2f9d317 100644 --- a/libudpard/udpard.c +++ b/libudpard/udpard.c @@ -654,15 +654,10 @@ struct UdpardTxItem* udpardTxPeek(const struct UdpardTx* const self) return out; } -struct UdpardTxItem* udpardTxPop(struct UdpardTx* const self, const struct UdpardTxItem* const item) +struct UdpardTxItem* udpardTxPop(struct UdpardTx* const self, struct UdpardTxItem* const item) { - struct UdpardTxItem* out = NULL; if ((self != NULL) && (item != NULL)) { - // Intentional violation of MISRA: casting away const qualifier. This is considered safe because the API - // contract dictates that the pointer shall point to a mutable entity in RAM previously allocated by the - // memory manager. It is difficult to avoid this cast in this context. - out = (struct UdpardTxItem*) item; // NOSONAR casting away const qualifier. // Paragraph 6.7.2.1.15 of the C standard says: // A pointer to a structure object, suitably converted, points to its initial member, and vice versa. // Note that the highest-priority frame is always a leaf node in the AVL tree, which means that it is very @@ -671,7 +666,7 @@ struct UdpardTxItem* udpardTxPop(struct UdpardTx* const self, const struct Udpar UDPARD_ASSERT(self->queue_size > 0U); self->queue_size--; } - return out; + return item; } void udpardTxFree(const struct UdpardTxMemoryResources memory, struct UdpardTxItem* const item) diff --git a/libudpard/udpard.h b/libudpard/udpard.h index 20d5f18..9cd22f5 100644 --- a/libudpard/udpard.h +++ b/libudpard/udpard.h @@ -669,7 +669,7 @@ struct UdpardTxItem* udpardTxPeek(const struct UdpardTx* const self); /// If any of the arguments are NULL, the function has no effect and returns NULL. /// /// The time complexity is logarithmic of the queue size. This function does not invoke the dynamic memory manager. -struct UdpardTxItem* udpardTxPop(struct UdpardTx* const self, const struct UdpardTxItem* const item); +struct UdpardTxItem* udpardTxPop(struct UdpardTx* const self, struct UdpardTxItem* const item); /// This is a simple helper that frees the memory allocated for the item and its payload, /// using the correct sizes and memory resources. diff --git a/tests/src/test_e2e.cpp b/tests/src/test_e2e.cpp index a90fa3d..8ea7800 100644 --- a/tests/src/test_e2e.cpp +++ b/tests/src/test_e2e.cpp @@ -164,7 +164,7 @@ void testPubSub() TEST_ASSERT_EQUAL(0, alloc_rx_session.allocated_fragments); TEST_ASSERT_EQUAL(0, alloc_rx_fragment.allocated_fragments); TEST_ASSERT_EQUAL(0, alloc_rx_payload.allocated_fragments); - const UdpardTxItem* tx_item = udpardTxPeek(&tx); + UdpardTxItem* tx_item = udpardTxPeek(&tx); TEST_ASSERT_NOT_NULL(tx_item); TEST_ASSERT_EQUAL(sub.at(1).udp_ip_endpoint.ip_address, tx_item->destination.ip_address); TEST_ASSERT_NULL(tx_item->next_in_transfer); @@ -478,7 +478,7 @@ void testRPC() TEST_ASSERT_EQUAL(0, alloc_rx_session.allocated_fragments); TEST_ASSERT_EQUAL(0, alloc_rx_fragment.allocated_fragments); TEST_ASSERT_EQUAL(0, alloc_rx_payload.allocated_fragments); - const UdpardTxItem* tx_item = udpardTxPeek(&tx); + UdpardTxItem* tx_item = udpardTxPeek(&tx); TEST_ASSERT_NOT_NULL(tx_item); TEST_ASSERT_EQUAL(udp_ip_endpoint.ip_address, tx_item->destination.ip_address); TEST_ASSERT_NULL(tx_item->next_in_transfer); diff --git a/tests/src/test_intrusive_tx.c b/tests/src/test_intrusive_tx.c index 2618aa5..f3ac844 100644 --- a/tests/src/test_intrusive_tx.c +++ b/tests/src/test_intrusive_tx.c @@ -642,7 +642,7 @@ static void testPushPeekPopFree(void) alloc.allocated_bytes); TEST_ASSERT_EQUAL(3, tx.queue_size); - const UdpardTxItem* frame = udpardTxPeek(&tx); + UdpardTxItem* frame = udpardTxPeek(&tx); TEST_ASSERT_NOT_EQUAL(NULL, frame); TEST_ASSERT_NOT_EQUAL(NULL, frame->next_in_transfer); TEST_ASSERT_EQUAL(1234567890U, frame->deadline_usec); @@ -722,7 +722,7 @@ static void testPushPrioritization(void) NULL)); TEST_ASSERT_EQUAL(3 * 2ULL, alloc.allocated_fragments); TEST_ASSERT_EQUAL(3, tx.queue_size); - const UdpardTxItem* frame = udpardTxPeek(&tx); + UdpardTxItem* frame = udpardTxPeek(&tx); TEST_ASSERT_NOT_EQUAL(NULL, frame); TEST_ASSERT_EQUAL(0xAAAAAAAA, frame->destination.ip_address); diff --git a/tests/src/test_tx.cpp b/tests/src/test_tx.cpp index 7ca4c10..5f5a025 100644 --- a/tests/src/test_tx.cpp +++ b/tests/src/test_tx.cpp @@ -113,7 +113,7 @@ void testPublish() &user_transfer_referent)); TEST_ASSERT_EQUAL(1 * 2ULL, alloc.allocated_fragments); TEST_ASSERT_EQUAL(1, tx.queue_size); - const auto* frame = udpardTxPeek(&tx); + auto* frame = udpardTxPeek(&tx); std::cout << hexdump::hexdump(frame->datagram_payload.data, frame->datagram_payload.size) << "\n\n"; TEST_ASSERT_NOT_EQUAL(nullptr, frame); TEST_ASSERT_EQUAL(nullptr, frame->next_in_transfer); @@ -249,7 +249,7 @@ void testRequest() &user_transfer_referent)); TEST_ASSERT_EQUAL(1 * 2ULL, alloc.allocated_fragments); TEST_ASSERT_EQUAL(1, tx.queue_size); - const auto* frame = udpardTxPeek(&tx); + auto* frame = udpardTxPeek(&tx); std::cout << hexdump::hexdump(frame->datagram_payload.data, frame->datagram_payload.size) << "\n\n"; TEST_ASSERT_NOT_EQUAL(nullptr, frame); TEST_ASSERT_EQUAL(nullptr, frame->next_in_transfer); @@ -401,7 +401,7 @@ void testRespond() &user_transfer_referent)); TEST_ASSERT_EQUAL(1 * 2ULL, alloc.allocated_fragments); TEST_ASSERT_EQUAL(1, tx.queue_size); - const auto* frame = udpardTxPeek(&tx); + auto* frame = udpardTxPeek(&tx); std::cout << hexdump::hexdump(frame->datagram_payload.data, frame->datagram_payload.size) << "\n\n"; TEST_ASSERT_NOT_EQUAL(nullptr, frame); TEST_ASSERT_EQUAL(nullptr, frame->next_in_transfer);