1
0
mirror of git://projects.qi-hardware.com/wernermisc.git synced 2024-12-27 03:18:58 +02:00
wernermisc/m1/patches/rtems/rbtree-container-of.patch

33 lines
1.2 KiB
Diff

This issue is under review:
https://www.rtems.org/bugzilla/show_bug.cgi?id=1963
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
RTEMS with this patch applied runs well (on Milkymist), but I don't
know if the code in question actually is executed.
- Werner
Index: rtems/cpukit/score/include/rtems/score/rbtree.h
===================================================================
--- rtems.orig/cpukit/score/include/rtems/score/rbtree.h 2011-11-12 08:52:50.000000000 -0300
+++ rtems/cpukit/score/include/rtems/score/rbtree.h 2011-11-12 09:00:35.000000000 -0300
@@ -90,7 +90,9 @@
*
*/
#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.