Skip to content

Commit 142590d

Browse files
committed
udpardTxPop now accepts mutable item #sonar
1 parent 01b14e7 commit 142590d

File tree

5 files changed

+10
-15
lines changed

5 files changed

+10
-15
lines changed

libudpard/udpard.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -654,15 +654,10 @@ struct UdpardTxItem* udpardTxPeek(const struct UdpardTx* const self)
654654
return out;
655655
}
656656

657-
struct UdpardTxItem* udpardTxPop(struct UdpardTx* const self, const struct UdpardTxItem* const item)
657+
struct UdpardTxItem* udpardTxPop(struct UdpardTx* const self, struct UdpardTxItem* const item)
658658
{
659-
struct UdpardTxItem* out = NULL;
660659
if ((self != NULL) && (item != NULL))
661660
{
662-
// Intentional violation of MISRA: casting away const qualifier. This is considered safe because the API
663-
// contract dictates that the pointer shall point to a mutable entity in RAM previously allocated by the
664-
// memory manager. It is difficult to avoid this cast in this context.
665-
out = (struct UdpardTxItem*) item; // NOSONAR casting away const qualifier.
666661
// Paragraph 6.7.2.1.15 of the C standard says:
667662
// A pointer to a structure object, suitably converted, points to its initial member, and vice versa.
668663
// 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
671666
UDPARD_ASSERT(self->queue_size > 0U);
672667
self->queue_size--;
673668
}
674-
return out;
669+
return item;
675670
}
676671

677672
void udpardTxFree(const struct UdpardTxMemoryResources memory, struct UdpardTxItem* const item)

libudpard/udpard.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ struct UdpardTxItem* udpardTxPeek(const struct UdpardTx* const self);
669669
/// If any of the arguments are NULL, the function has no effect and returns NULL.
670670
///
671671
/// The time complexity is logarithmic of the queue size. This function does not invoke the dynamic memory manager.
672-
struct UdpardTxItem* udpardTxPop(struct UdpardTx* const self, const struct UdpardTxItem* const item);
672+
struct UdpardTxItem* udpardTxPop(struct UdpardTx* const self, struct UdpardTxItem* const item);
673673

674674
/// This is a simple helper that frees the memory allocated for the item and its payload,
675675
/// using the correct sizes and memory resources.

tests/src/test_e2e.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ void testPubSub()
164164
TEST_ASSERT_EQUAL(0, alloc_rx_session.allocated_fragments);
165165
TEST_ASSERT_EQUAL(0, alloc_rx_fragment.allocated_fragments);
166166
TEST_ASSERT_EQUAL(0, alloc_rx_payload.allocated_fragments);
167-
const UdpardTxItem* tx_item = udpardTxPeek(&tx);
167+
UdpardTxItem* tx_item = udpardTxPeek(&tx);
168168
TEST_ASSERT_NOT_NULL(tx_item);
169169
TEST_ASSERT_EQUAL(sub.at(1).udp_ip_endpoint.ip_address, tx_item->destination.ip_address);
170170
TEST_ASSERT_NULL(tx_item->next_in_transfer);
@@ -478,7 +478,7 @@ void testRPC()
478478
TEST_ASSERT_EQUAL(0, alloc_rx_session.allocated_fragments);
479479
TEST_ASSERT_EQUAL(0, alloc_rx_fragment.allocated_fragments);
480480
TEST_ASSERT_EQUAL(0, alloc_rx_payload.allocated_fragments);
481-
const UdpardTxItem* tx_item = udpardTxPeek(&tx);
481+
UdpardTxItem* tx_item = udpardTxPeek(&tx);
482482
TEST_ASSERT_NOT_NULL(tx_item);
483483
TEST_ASSERT_EQUAL(udp_ip_endpoint.ip_address, tx_item->destination.ip_address);
484484
TEST_ASSERT_NULL(tx_item->next_in_transfer);

tests/src/test_intrusive_tx.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ static void testPushPeekPopFree(void)
642642
alloc.allocated_bytes);
643643
TEST_ASSERT_EQUAL(3, tx.queue_size);
644644

645-
const UdpardTxItem* frame = udpardTxPeek(&tx);
645+
UdpardTxItem* frame = udpardTxPeek(&tx);
646646
TEST_ASSERT_NOT_EQUAL(NULL, frame);
647647
TEST_ASSERT_NOT_EQUAL(NULL, frame->next_in_transfer);
648648
TEST_ASSERT_EQUAL(1234567890U, frame->deadline_usec);
@@ -722,7 +722,7 @@ static void testPushPrioritization(void)
722722
NULL));
723723
TEST_ASSERT_EQUAL(3 * 2ULL, alloc.allocated_fragments);
724724
TEST_ASSERT_EQUAL(3, tx.queue_size);
725-
const UdpardTxItem* frame = udpardTxPeek(&tx);
725+
UdpardTxItem* frame = udpardTxPeek(&tx);
726726
TEST_ASSERT_NOT_EQUAL(NULL, frame);
727727
TEST_ASSERT_EQUAL(0xAAAAAAAA, frame->destination.ip_address);
728728

tests/src/test_tx.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ void testPublish()
113113
&user_transfer_referent));
114114
TEST_ASSERT_EQUAL(1 * 2ULL, alloc.allocated_fragments);
115115
TEST_ASSERT_EQUAL(1, tx.queue_size);
116-
const auto* frame = udpardTxPeek(&tx);
116+
auto* frame = udpardTxPeek(&tx);
117117
std::cout << hexdump::hexdump(frame->datagram_payload.data, frame->datagram_payload.size) << "\n\n";
118118
TEST_ASSERT_NOT_EQUAL(nullptr, frame);
119119
TEST_ASSERT_EQUAL(nullptr, frame->next_in_transfer);
@@ -249,7 +249,7 @@ void testRequest()
249249
&user_transfer_referent));
250250
TEST_ASSERT_EQUAL(1 * 2ULL, alloc.allocated_fragments);
251251
TEST_ASSERT_EQUAL(1, tx.queue_size);
252-
const auto* frame = udpardTxPeek(&tx);
252+
auto* frame = udpardTxPeek(&tx);
253253
std::cout << hexdump::hexdump(frame->datagram_payload.data, frame->datagram_payload.size) << "\n\n";
254254
TEST_ASSERT_NOT_EQUAL(nullptr, frame);
255255
TEST_ASSERT_EQUAL(nullptr, frame->next_in_transfer);
@@ -401,7 +401,7 @@ void testRespond()
401401
&user_transfer_referent));
402402
TEST_ASSERT_EQUAL(1 * 2ULL, alloc.allocated_fragments);
403403
TEST_ASSERT_EQUAL(1, tx.queue_size);
404-
const auto* frame = udpardTxPeek(&tx);
404+
auto* frame = udpardTxPeek(&tx);
405405
std::cout << hexdump::hexdump(frame->datagram_payload.data, frame->datagram_payload.size) << "\n\n";
406406
TEST_ASSERT_NOT_EQUAL(nullptr, frame);
407407
TEST_ASSERT_EQUAL(nullptr, frame->next_in_transfer);

0 commit comments

Comments
 (0)