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

Note that I haven't tried building RTEMS yet, so the patch is completely
untested.

- 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@Freenode

Reply via email to