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))
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)
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;
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);
}
if (tc == NULL) {
- char *ptr;
+ uint8_t *ptr = NULL;
+ union talloc_chunk_cast_u tcc;
/*
* Only do the memlimit check/update on actual allocation.
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;