Skip to content

Commit 94fe001

Browse files
canard: clarify v0 spool tail handling for cppcheck
1 parent 1779889 commit 94fe001

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

libcanard/canard.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -648,21 +648,23 @@ static tx_frame_t* tx_spool_v0(canard_t* const self,
648648
size_t offset = 0U;
649649
while (offset < size_total) {
650650
tx_frame_t* const item = tx_frame_new(self, smaller((size_total - offset) + 1U, CANARD_MTU_CAN_CLASSIC));
651-
if (NULL == head) {
652-
head = item;
653-
} else {
654-
tail->next = item;
655-
}
656-
tail = item;
657651
// On OOM, deallocate the entire chain and quit.
658-
if (NULL == tail) {
652+
if (NULL == item) {
659653
while (head != NULL) {
660654
tx_frame_t* const next = head->next;
661655
canard_refcount_dec(self, tx_frame_view(head));
662656
head = next;
663657
}
664658
break;
665659
}
660+
// Append the new item.
661+
if (NULL == head) {
662+
head = item;
663+
} else {
664+
CANARD_ASSERT(NULL != tail);
665+
tail->next = item;
666+
}
667+
tail = item;
666668
// Populate the frame contents.
667669
const size_t progress = smaller(size_total - offset, canard_dlc_to_len[tail->dlc] - 1U);
668670
bytes_chain_read(&reader, progress, tail->data);

0 commit comments

Comments
 (0)