[PATCH rtems-docs] c-user/chains: Correct iteration example code
Chris Johns
chrisj at rtems.org
Thu Mar 9 01:40:14 UTC 2023
On 9/3/2023 7:22 am, Kinsey Moore wrote:
> On Wed, Mar 8, 2023 at 3:47 PM Chris Johns <chrisj at rtems.org
> <mailto:chrisj at rtems.org>> wrote:
> On 9/3/2023 5:40 am, Kinsey Moore wrote:
> > 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.
> > ---
> > c-user/chains.rst | 4 ++++
> > 1 file changed, 4 insertions(+)
> >
> > diff --git a/c-user/chains.rst b/c-user/chains.rst
> > index f518ef4..e791d10 100644
> > --- a/c-user/chains.rst
> > +++ b/c-user/chains.rst
> > @@ -193,6 +193,10 @@ placed on another chain:
> > rtems_chain_initialize_empty (out);
> >
> > node = rtems_chain_head (chain);
> > +
> > + /* The node returned by rtems_chain_head() is owned by the chain */
> > + node = node->next;
>
> node = rtems_chain_next (node); ?
>
> node->next is used slightly further down in the example, but I can change it to
> rtems_chain_next for both if you prefer.
Thanks. I think making all references use the API in the example is a good thing.
Chris
More information about the devel
mailing list