summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <asn@samba.org>2018-10-12 11:58:26 +0200
committerAndreas Schneider <asn@cryptomilk.org>2019-03-19 12:38:50 +0000
commitb2c2c4c3e6c4538c62cbcf03923bd7536292f7e9 (patch)
treebc27734fa41d0c5faae76036e517ad2ed0539deb
parent7d4865610f9542555c212540c35d98536c1f37e7 (diff)
downloadsamba-b2c2c4c3e6c4538c62cbcf03923bd7536292f7e9.tar.gz
talloc: Fix alignment issues for casting pointers
warning: cast from 'char *' to 'struct talloc_chunk *' increases required alignment from 1 to 8 Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org> Autobuild-Date(master): Tue Mar 19 12:38:50 UTC 2019 on sn-devel-144
-rw-r--r--lib/talloc/talloc.c30
1 files changed, 25 insertions, 5 deletions
diff --git a/lib/talloc/talloc.c b/lib/talloc/talloc.c
index 073a3e50d4b..518ffbdbfdf 100644
--- a/lib/talloc/talloc.c
+++ b/lib/talloc/talloc.c
@@ -317,6 +317,11 @@ struct talloc_chunk {
struct talloc_pool_hdr *pool;
};
+union talloc_chunk_cast_u {
+ uint8_t *ptr;
+ struct talloc_chunk *chunk;
+};
+
/* 16 byte alignment seems to keep everyone happy */
#define TC_ALIGN16(s) (((s)+15)&~15)
#define TC_HDR_SIZE TC_ALIGN16(sizeof(struct talloc_chunk))
@@ -611,16 +616,25 @@ struct talloc_pool_hdr {
size_t poolsize;
};
+union talloc_pool_hdr_cast_u {
+ uint8_t *ptr;
+ struct talloc_pool_hdr *hdr;
+};
+
#define TP_HDR_SIZE TC_ALIGN16(sizeof(struct talloc_pool_hdr))
static inline struct talloc_pool_hdr *talloc_pool_from_chunk(struct talloc_chunk *c)
{
- return (struct talloc_pool_hdr *)((char *)c - TP_HDR_SIZE);
+ union talloc_chunk_cast_u tcc = { .chunk = c };
+ union talloc_pool_hdr_cast_u tphc = { tcc.ptr - TP_HDR_SIZE };
+ return tphc.hdr;
}
static inline struct talloc_chunk *talloc_chunk_from_pool(struct talloc_pool_hdr *h)
{
- return (struct talloc_chunk *)((char *)h + TP_HDR_SIZE);
+ union talloc_pool_hdr_cast_u tphc = { .hdr = h };
+ union talloc_chunk_cast_u tcc = { .ptr = tphc.ptr + TP_HDR_SIZE };
+ return tcc.chunk;
}
static inline void *tc_pool_end(struct talloc_pool_hdr *pool_hdr)
@@ -668,6 +682,7 @@ static inline struct talloc_chunk *tc_alloc_pool(struct talloc_chunk *parent,
size_t size, size_t prefix_len)
{
struct talloc_pool_hdr *pool_hdr = NULL;
+ union talloc_chunk_cast_u tcc;
size_t space_left;
struct talloc_chunk *result;
size_t chunk_size;
@@ -698,7 +713,10 @@ static inline struct talloc_chunk *tc_alloc_pool(struct talloc_chunk *parent,
return NULL;
}
- result = (struct talloc_chunk *)((char *)pool_hdr->end + prefix_len);
+ tcc = (union talloc_chunk_cast_u) {
+ .ptr = ((uint8_t *)pool_hdr->end) + prefix_len
+ };
+ result = tcc.chunk;
#if defined(DEVELOPER) && defined(VALGRIND_MAKE_MEM_UNDEFINED)
VALGRIND_MAKE_MEM_UNDEFINED(pool_hdr->end, chunk_size);
@@ -750,7 +768,8 @@ static inline void *__talloc_with_prefix(const void *context,
}
if (tc == NULL) {
- char *ptr;
+ uint8_t *ptr = NULL;
+ union talloc_chunk_cast_u tcc;
/*
* Only do the memlimit check/update on actual allocation.
@@ -764,7 +783,8 @@ static inline void *__talloc_with_prefix(const void *context,
if (unlikely(ptr == NULL)) {
return NULL;
}
- tc = (struct talloc_chunk *)(ptr + prefix_len);
+ tcc = (union talloc_chunk_cast_u) { .ptr = ptr + prefix_len };
+ tc = tcc.chunk;
tc->flags = talloc_magic;
tc->pool = NULL;