107 lines
3.2 KiB
Diff
107 lines
3.2 KiB
Diff
From b2c2c4c3e6c4538c62cbcf03923bd7536292f7e9 Mon Sep 17 00:00:00 2001
|
|
From: Andreas Schneider <asn@samba.org>
|
|
Date: Fri, 12 Oct 2018 11:58:26 +0200
|
|
Subject: [PATCH 16/28] 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
|
|
|
|
Signed-off-by: root <root@localhost.localdomain>
|
|
---
|
|
talloc.c | 30 +++++++++++++++++++++++++-----
|
|
1 file changed, 25 insertions(+), 5 deletions(-)
|
|
|
|
diff --git a/talloc.c b/talloc.c
|
|
index 073a3e50d4b..518ffbdbfdf 100644
|
|
--- a/talloc.c
|
|
+++ b/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;
|
|
|
|
--
|
|
2.19.1
|
|
|