The branch, master has been updated
       via  b2c2c4c3e6c talloc: Fix alignment issues for casting pointers
      from  7d4865610f9 vfs_nfs4acl_xattr: check status for 
NT_STATUS_ACCESS_DENIED in take ownership override

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit b2c2c4c3e6c4538c62cbcf03923bd7536292f7e9
Author: Andreas Schneider <[email protected]>
Date:   Fri Oct 12 11:58:26 2018 +0200

    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 <[email protected]>
    Reviewed-by: Volker Lendecke <[email protected]>
    
    Autobuild-User(master): Andreas Schneider <[email protected]>
    Autobuild-Date(master): Tue Mar 19 12:38:50 UTC 2019 on sn-devel-144

-----------------------------------------------------------------------

Summary of changes:
 lib/talloc/talloc.c | 30 +++++++++++++++++++++++++-----
 1 file changed, 25 insertions(+), 5 deletions(-)


Changeset truncated at 500 lines:

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;
 


-- 
Samba Shared Repository

Reply via email to