Module Name:    src
Committed By:   christos
Date:           Sat May  9 18:49:36 UTC 2015

Modified Files:
        src/sys/lib/libkern: libkern.h

Log Message:
tricks with sizeof() make coverity complain.


To generate a diff of this commit:
cvs rdiff -u -r1.118 -r1.119 src/sys/lib/libkern/libkern.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/lib/libkern/libkern.h
diff -u src/sys/lib/libkern/libkern.h:1.118 src/sys/lib/libkern/libkern.h:1.119
--- src/sys/lib/libkern/libkern.h:1.118	Mon Apr 20 11:22:17 2015
+++ src/sys/lib/libkern/libkern.h	Sat May  9 14:49:36 2015
@@ -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 @@ tolower(int ch)
  *
  * 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 {

Reply via email to