Possible problems with _RBTree_Container_of
Sébastien Bourdeauducq
sebastien at milkymist.org
Tue Nov 8 22:06:59 UTC 2011
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
More information about the users
mailing list