[PATCH rtems-docs v2] c-user/chains: Correct iteration example code

Chris Johns chrisj at rtems.org
Thu Mar 9 21:52:45 UTC 2023


On 10/3/2023 10:12 pm, Kinsey Moore wrote:
> On Thu, Mar 9, 2023 at 1:01 AM Sebastian Huber
> <sebastian.huber at embedded-brains.de <mailto:sebastian.huber at embedded-brains.de>>
> wrote:
>     On 09.03.23 03:33, 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 | 6 +++++-
>     >   1 file changed, 5 insertions(+), 1 deletion(-)
>     >
>     > diff --git a/c-user/chains.rst b/c-user/chains.rst
>     > index f518ef4..2044966 100644
>     > --- a/c-user/chains.rst
>     > +++ b/c-user/chains.rst
>     > @@ -193,10 +193,14 @@ 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 = rtems_chain_next(node);
> 
>     You can simply use rtems_chain_first() instead of this head/next
>     combination.
> 
> Thanks, I'll make that improvement before committing!

Nice :)

Chris


More information about the devel mailing list