summaryrefslogtreecommitdiffstats
path: root/c-user
diff options
context:
space:
mode:
authorKinsey Moore <kinsey.moore@oarcorp.com>2023-03-08 14:39:25 -0600
committerJoel Sherrill <joel@rtems.org>2023-03-09 09:16:12 -0600
commitfd6d862033961da3c8d9190033121472b7692297 (patch)
tree74e982caa9be3fa0615e1ce11539413c27443efe /c-user
parentwaf: Update to waf 2.0.25 (diff)
downloadrtems-docs-fd6d862033961da3c8d9190033121472b7692297.tar.bz2
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.
Diffstat (limited to 'c-user')
-rw-r--r--c-user/chains.rst5
1 files changed, 3 insertions, 2 deletions
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);