Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/lib/libkern tricks with sizeof() make coverity complain.



details:   https://anonhg.NetBSD.org/src/rev/15a30a970935
branches:  trunk
changeset: 808214:15a30a970935
user:      christos <christos%NetBSD.org@localhost>
date:      Sat May 09 18:49:36 2015 +0000

description:
tricks with sizeof() make coverity complain.

diffstat:

 sys/lib/libkern/libkern.h |  17 ++++++++++++-----
 1 files changed, 12 insertions(+), 5 deletions(-)

diffs (33 lines):

diff -r 827601fa184d -r 15a30a970935 sys/lib/libkern/libkern.h
--- a/sys/lib/libkern/libkern.h Sat May 09 18:48:14 2015 +0000
+++ b/sys/lib/libkern/libkern.h Sat May 09 18:49:36 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: libkern.h,v 1.118 2015/04/20 15:22:17 riastradh Exp $  */
+/*     $NetBSD: libkern.h,v 1.119 2015/05/09 18:49:36 christos Exp $   */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -329,12 +329,19 @@
  *
  * The 0*sizeof((PTR) - ...) causes the compiler to warn if the type of
  * *fp does not match the type of struct bar::b_foo.
+ * We skip the validation for coverity runs to avoid warnings.
  */
+#ifdef __COVERITY__
+#define __validate_container_of(PTR, TYPE, FIELD) 0
+#else
+#define __validate_container_of(PTR, TYPE, FIELD)                      \
+    (0 * sizeof((PTR) - &((TYPE *)(((char *)(PTR)) -                   \
+    offsetof(TYPE, FIELD)))->FIELD))
+#endif
+
 #define        container_of(PTR, TYPE, FIELD)                                  \
-       ((TYPE *)(((char *)(PTR)) - offsetof(TYPE, FIELD) +             \
-           0*sizeof((PTR) -                                            \
-               &((TYPE *)(((char *)(PTR)) -                            \
-                       offsetof(TYPE, FIELD)))->FIELD)))
+    ((TYPE *)(((char *)(PTR)) - offsetof(TYPE, FIELD))                 \
+       + __validate_container_of(PTR, TYPE, FIELD))
 
 #define        MTPRNG_RLEN             624
 struct mtprng_state {



Home | Main Index | Thread Index | Old Index