c-user/chains: Correct iteration example code

Casting the node returned by rtems_chain_head is incorrect. That node is
owned by the control structure and use of it post-cast could cause
memory corruption. Instead, use rtems_chain_first which returns the
node after the head node. This also corrects node->next to
rtems_chain_next(node) which makes better use of the API.
This commit is contained in:
Kinsey Moore
2023-03-08 14:39:25 -06:00
committed by Joel Sherrill
parent 2f7ebf719d
commit fd6d862033

View File

@@ -192,11 +192,12 @@ placed on another chain:
rtems_chain_initialize_empty (out);
node = rtems_chain_head (chain);
node = rtems_chain_first (chain);
while (!rtems_chain_is_tail (chain, node))
{
bar = (foo*) node;
rtems_chain_node* next_node = node->next;
rtems_chain_node* next_node = rtems_chain_next(node);
if (strcmp (match, bar->data) == 0)
{
rtems_chain_extract (node);