From 021b386ddac3384643d9342683cb448047f83a1a Mon Sep 17 00:00:00 2001 From: Johannes Löthberg Date: Sun, 18 Jan 2015 15:46:39 +0100 Subject: sdsheader: cast pointer through void pointer Because a char* and struct sdshdr pointer have a different alignment you get the following warning when try to cast it directly: warning: cast from 'sds' (aka 'char *') to 'struct sdshdr *' increases required alignment from 1 to 8 [-Wcast-align] To silence the warning we cast it to a void pointer first. --- src/sds.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/sds.h b/src/sds.h index a46b06b..d0830fe 100644 --- a/src/sds.h +++ b/src/sds.h @@ -43,7 +43,9 @@ struct sdshdr { }; static inline struct sdshdr * sdsheader(const sds s) { - return s - (sizeof (struct sdshdr)); + /* The sdshdr pointer has a different alignment than the original char + * pointer, so cast it through a void pointer to silence the warning. */ + return (void *)(s - (sizeof (struct sdshdr))); } static inline size_t sdslen(const sds s) { -- cgit v1.2.3-54-g00ecf