diff options
author | Johannes Löthberg <johannes@kyriasis.com> | 2015-01-18 15:46:39 +0100 |
---|---|---|
committer | Johannes Löthberg <johannes@kyriasis.com> | 2015-01-19 00:25:41 +0100 |
commit | 021b386ddac3384643d9342683cb448047f83a1a (patch) | |
tree | a2ba38467dd2b53e90274597afa9771ddf64b40d | |
parent | 5079d22319930f47647d1ed9507ad07ec0b922d0 (diff) | |
download | sds-021b386ddac3384643d9342683cb448047f83a1a.tar.xz |
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.
-rw-r--r-- | src/sds.h | 4 |
1 files changed, 3 insertions, 1 deletions
@@ -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) { |