mirror of
https://git.rtems.org/rtems-docs/
synced 2025-10-18 05:58:21 +08:00
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:

committed by
Joel Sherrill

parent
2f7ebf719d
commit
fd6d862033
@@ -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);
|
||||
|
Reference in New Issue
Block a user