util: Fix GCC false-positive warning for CONTAINER_OF.
authorBen Pfaff <blp@nicira.com>
Fri, 7 May 2010 00:04:11 +0000 (17:04 -0700)
committerBen Pfaff <blp@nicira.com>
Fri, 7 May 2010 21:36:01 +0000 (14:36 -0700)
On sparc, GCC would issue the following warning for every use of
CONTAINER_OF:

    warning: cast increases required alignment of target type

This is a false positive: assuming that the data structure that it is
applied to was allocated properly, the use of CONTAINER_OF to reach it is
valid.  And if it was not allocated properly, then code that accesses it
other ways will have trouble too.

lib/util.h

index 9df6db5..0e9353d 100644 (file)
@@ -80,7 +80,7 @@ extern const char *program_name;
 /* Given POINTER, the address of the given MEMBER in a STRUCT object, returns
    the STRUCT object. */
 #define CONTAINER_OF(POINTER, STRUCT, MEMBER)                           \
-        ((STRUCT *) ((char *) (POINTER) - offsetof (STRUCT, MEMBER)))
+        ((STRUCT *) (void *) ((char *) (POINTER) - offsetof (STRUCT, MEMBER)))
 
 #ifdef  __cplusplus
 extern "C" {