From fd6d862033961da3c8d9190033121472b7692297 Mon Sep 17 00:00:00 2001 From: Kinsey Moore Date: Wed, 8 Mar 2023 14:39:25 -0600 Subject: 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. --- c-user/chains.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'c-user') diff --git a/c-user/chains.rst b/c-user/chains.rst index f518ef4..ca80b4b 100644 --- a/c-user/chains.rst +++ b/c-user/chains.rst @@ -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); -- cgit v1.2.3