Possible problems with _RBTree_Container_of

Gedare Bloom gedare at rtems.org
Tue Nov 8 22:59:46 UTC 2011


Hi Sebastien,

I originally wrote this code, but I casted the node to a size_t. It
looks like the macro was changed recently without a PR so I must have
missed it in the VC logs and will take a look.

The possible problem isn't really solved by casting to void*, though
it might make a warning I think if a pointer is not given as node then
the address will not be taken and container_of still comes up with a
bad address. I'll think about this some more...

Thanks!
Gedare

On Tue, Nov 8, 2011 at 5:06 PM, Sébastien Bourdeauducq
<sebastien at milkymist.org> wrote:
> Any comments?
> Thanks,
> Sébastien
>
> -------- Original Message --------
> Subject: [Milkymist-devel] likely bug in RTEMS CVS
> Date: Mon, 7 Nov 2011 19:26:45 -0300
> From: Werner Almesberger <werner at almesberger.net>
> Reply-To: Milkymist One, Milkymist SoC and Flickernoise developers' list
> <devel at lists.milkymist.org>
> To: Milkymist One, Milkymist SoC and Flickernoise developers' list
> <devel at lists.milkymist.org>
>
> I'm looking at diffs between the CVS version of RTEMS and the version
> in our SDK. One change in cpukit/score/include/rtems/score/rbtree.h
> looks highly suspicious. Below is a patch that should improve it.
>
> There seem to be two issues in the original code:
>
> - the "node" argument of the macro is not protected, which could lead
>  to very hard to find errors (this doesn't seem to cause any
>  immediate problems just now, but it's a lousy risk to take)
>
> - more seriously, "offsetof" counts in bytes while arithmentic on the
>  "node" pointer counts in multiples of whatever size that object has
>
>
> - Werner
>
> Index: rbtree.h
> ===================================================================
> RCS file: /usr1/CVS/rtems/cpukit/score/include/rtems/score/rbtree.h,v
> retrieving revision 1.7
> diff -u -r1.7 rbtree.h
> --- rbtree.h    20 Oct 2011 11:58:54 -0000      1.7
> +++ rbtree.h    7 Nov 2011 22:10:40 -0000
> @@ -90,7 +90,8 @@
>  *
>  */
>  #define _RBTree_Container_of(node,container_type, node_field_name) \
> -  ((container_type*) (node - offsetof(container_type,node_field_name)))
> +  ((container_type*) ((void *) (node) - \
> +    offsetof(container_type,node_field_name)))
>
>  /**
>  *  This type indicates the direction.
> _______________________________________________
> http://lists.milkymist.org/listinfo.cgi/devel-milkymist.org
> IRC: #milkymist at Freenode
> _______________________________________________
> rtems-users mailing list
> rtems-users at rtems.org
> http://www.rtems.org/mailman/listinfo/rtems-users
>




More information about the users mailing list