aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJohannes Löthberg <johannes@kyriasis.com>2015-01-18 15:46:39 +0100
committerJohannes Löthberg <johannes@kyriasis.com>2015-01-19 00:25:41 +0100
commit021b386ddac3384643d9342683cb448047f83a1a (patch)
treea2ba38467dd2b53e90274597afa9771ddf64b40d /src
parent5079d22319930f47647d1ed9507ad07ec0b922d0 (diff)
downloadsds-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.
Diffstat (limited to 'src')
-rw-r--r--src/sds.h4
1 files changed, 3 insertions, 1 deletions
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) {