summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorRuediger Meier2018-12-02 19:23:45 +0100
committerKarel Zak2018-12-03 10:29:56 +0100
commit1866fa6a596af6b85506f2ac35242d60decfb14d (patch)
tree4cb30975f25da4a91aa47278800daeec264df072 /include
parenttests: make lsns-netnsid portable (diff)
downloadkernel-qcow2-util-linux-1866fa6a596af6b85506f2ac35242d60decfb14d.tar.gz
kernel-qcow2-util-linux-1866fa6a596af6b85506f2ac35242d60decfb14d.tar.xz
kernel-qcow2-util-linux-1866fa6a596af6b85506f2ac35242d60decfb14d.zip
include/c: re-add type checking in container_of()
This reverts parts of commit eb06d5d4, which seems to be based on Linux kernel commit c7acec71. Unlike the original kernel patch we did not add that even stronger type checking by using macro BUILD_BUG_ON_MSG. So basically we removed a useful warning when compiling such broken code: struct st { int a; char b; }; struct st t = { .a = 1, .b = 2 }; struct st *x = container_of(&t.a, struct st, b); printf("%p %p\n", (void *)&t, (void *)x); Moreover we also introduced a new compiler warning for intel/icc: "arithmetic on pointer to void or function type" Let's just revert the update of container_of() because adding a kernel-like BUILD_BUG_ON_MSG would be too much noise and also problematic (see kernel commit c03567a8). Also note that the original problem addressed by the kernel commit seems to be only reproducible with gcc 4.9, not with any later gcc nor clang,icc. Moreover, currently we have no such use-case in the UL sources anyways. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Diffstat (limited to 'include')
-rw-r--r--include/c.h4
1 files changed, 2 insertions, 2 deletions
diff --git a/include/c.h b/include/c.h
index 8b2a2d19a..f1e329819 100644
--- a/include/c.h
+++ b/include/c.h
@@ -147,8 +147,8 @@
*/
#ifndef container_of
#define container_of(ptr, type, member) __extension__ ({ \
- void *__mptr = (void *)(ptr); \
- ((type *)(__mptr - offsetof(type, member))); })
+ const __typeof__( ((type *)0)->member ) *__mptr = (ptr); \
+ (type *)( (char *)__mptr - offsetof(type,member) );})
#endif
#ifndef HAVE_PROGRAM_INVOCATION_SHORT_NAME