From: Ronnie Sahlberg <ronniesahlberg@gmail.com>
Subject: [PATCH] Handle a bunch of other compiler warnings on armv6
Origin: upstream, https://github.com/sahlberg/libsmb2/commit/55555e27e3e9d84503ff276ed7a1fb08c2c35019
Bug: https://github.com/sahlberg/libsmb2/issues/408
Last-Update: 2024-04-03

and similararchectures that can not handle unaligned accesses
and where pointer conversions cause compiler warnings when converting
a pointer to a larger type.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
---
 lib/alloc.c                     |  2 +-
 lib/dcerpc.c                    | 30 +++++++++++++++---------------
 lib/ntlmssp.c                   |  2 +-
 lib/pdu.c                       |  4 ++--
 lib/smb2-cmd-create.c           |  2 +-
 lib/smb2-cmd-negotiate.c        |  2 +-
 lib/smb2-cmd-query-directory.c  |  8 ++++----
 lib/smb2-cmd-tree-connect.c     |  2 +-
 lib/smb2-data-file-info.c       |  4 ++--
 lib/smb2-data-filesystem-info.c |  4 ++--
 lib/smb2-data-reparse-point.c   |  4 ++--
 11 files changed, 34 insertions(+), 34 deletions(-)

diff --git a/lib/alloc.c b/lib/alloc.c
index bd5c8aa..03f125b 100644
--- a/lib/alloc.c
+++ b/lib/alloc.c
@@ -68,7 +68,7 @@
 
 #define container_of(ptr, type, member) ({                      \
         const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
-        (type *)( (char *)__mptr - offsetof(type,member) );})
+        (type *)(void *)( (char *)__mptr - offsetof(type,member) );})
 
 struct smb2_alloc_entry {
         struct smb2_alloc_entry *next;
diff --git a/lib/dcerpc.c b/lib/dcerpc.c
index 8799ca0..5a31b6e 100644
--- a/lib/dcerpc.c
+++ b/lib/dcerpc.c
@@ -69,7 +69,7 @@
 
 #define container_of(ptr, type, member) ({                      \
         const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
-        (type *)( (char *)__mptr - offsetof(type,member) );})
+        (type *)(void *)( (char *)__mptr - offsetof(type,member) );})
 
 struct dcerpc_deferred_pointer {
         dcerpc_coder coder;
@@ -292,9 +292,9 @@ dcerpc_set_uint16(struct dcerpc_context *ctx, struct dcerpc_pdu *pdu,
                 return -1;
         }
         if (!(pdu->hdr.packed_drep[0] & DCERPC_DR_LITTLE_ENDIAN)) {
-                *(uint16_t *)(iov->buf + *offset) = htobe16(value);
+                *(uint16_t *)(void *)(iov->buf + *offset) = htobe16(value);
         } else {
-                *(uint16_t *)(iov->buf + *offset) = htole16(value);
+                *(uint16_t *)(void *)(iov->buf + *offset) = htole16(value);
         }
         *offset += 2;
 
@@ -311,9 +311,9 @@ dcerpc_set_uint32(struct dcerpc_context *ctx, struct dcerpc_pdu *pdu,
                 return -1;
         }
         if (!(pdu->hdr.packed_drep[0] & DCERPC_DR_LITTLE_ENDIAN)) {
-                *(uint32_t *)(iov->buf + *offset) = htobe32(value);
+                *(uint32_t *)(void *)(iov->buf + *offset) = htobe32(value);
         } else {
-                *(uint32_t *)(iov->buf + *offset) = htole32(value);
+                *(uint32_t *)(void *)(iov->buf + *offset) = htole32(value);
         }
         *offset += 4;
         return 0;
@@ -329,9 +329,9 @@ dcerpc_set_uint64(struct dcerpc_context *ctx, struct dcerpc_pdu *pdu,
                 return -1;
         }
         if (!(pdu->hdr.packed_drep[0] & DCERPC_DR_LITTLE_ENDIAN)) {
-                *(uint64_t *)(iov->buf + *offset) = htobe64(value);
+                *(uint64_t *)(void *)(iov->buf + *offset) = htobe64(value);
         } else {
-                *(uint64_t *)(iov->buf + *offset) = htole64(value);
+                *(uint64_t *)(void *)(iov->buf + *offset) = htole64(value);
         }
         *offset += 8;
         return 0;
@@ -361,9 +361,9 @@ dcerpc_get_uint16(struct dcerpc_context *ctx, struct dcerpc_pdu *pdu,
                 return -1;
         }
         if (!(pdu->hdr.packed_drep[0] & DCERPC_DR_LITTLE_ENDIAN)) {
-                val = be16toh(*(uint16_t *)(iov->buf + *offset));
+                val = be16toh(*(uint16_t *)(void *)(iov->buf + *offset));
         } else {
-                val = le16toh(*(uint16_t *)(iov->buf + *offset));
+                val = le16toh(*(uint16_t *)(void *)(iov->buf + *offset));
         }
         *value = val;
         *offset += 2;
@@ -383,9 +383,9 @@ dcerpc_get_uint32(struct dcerpc_context *ctx, struct dcerpc_pdu *pdu,
         }
         
         if (!(pdu->hdr.packed_drep[0] & DCERPC_DR_LITTLE_ENDIAN)) {
-                val = be32toh(*(uint32_t *)(iov->buf + *offset));
+                val = be32toh(*(uint32_t *)(void *)(iov->buf + *offset));
         } else {
-                val = le32toh(*(uint32_t *)(iov->buf + *offset));
+                val = le32toh(*(uint32_t *)(void *)(iov->buf + *offset));
         }
         *value = val;
         *offset += 4;
@@ -404,9 +404,9 @@ dcerpc_get_uint64(struct dcerpc_context *ctx, struct dcerpc_pdu *pdu,
                 return -1;
         }
         if (!(pdu->hdr.packed_drep[0] & DCERPC_DR_LITTLE_ENDIAN)) {
-                val = be64toh(*(uint64_t *)(iov->buf + *offset));
+                val = be64toh(*(uint64_t *)(void *)(iov->buf + *offset));
         } else {
-                val = le64toh(*(uint64_t *)(iov->buf + *offset));
+                val = le64toh(*(uint64_t *)(void *)(iov->buf + *offset));
         }
         *value = val;
         *offset += 8;
@@ -1053,10 +1053,10 @@ dcerpc_decode_utf16(struct dcerpc_context *ctx, struct dcerpc_pdu *pdu,
                         if (dcerpc_get_uint16(ctx, pdu, iov, &o, &v)) {
                                 return -1;
                         }
-                        *(uint16_t *)&iov->buf[*offset + i * 2] = v;
+                        *(uint16_t *)(void *)&iov->buf[*offset + i * 2] = v;
                 }
         }
-        tmp = smb2_utf16_to_utf8((uint16_t *)(&iov->buf[*offset]), (size_t)s->actual_count);
+        tmp = smb2_utf16_to_utf8((uint16_t *)(void *)(&iov->buf[*offset]), (size_t)s->actual_count);
         *offset += (int)s->actual_count * 2;
 
         str = smb2_alloc_data(ctx->smb2, pdu->payload, strlen(tmp) + 1);
diff --git a/lib/ntlmssp.c b/lib/ntlmssp.c
index d309362..ec015a3 100644
--- a/lib/ntlmssp.c
+++ b/lib/ntlmssp.c
@@ -999,7 +999,7 @@ ntlmssp_get_utf16_field(uint8_t *input_buf, int input_len, int offset, char **re
         memcpy(&u32, &input_buf[offset + 4], 4);
         field_off = le32toh(u32);
         if (field_len && field_off) {
-                *result = (char*)smb2_utf16_to_utf8((uint16_t*)(input_buf + field_off), field_len / 2);
+                *result = (char*)smb2_utf16_to_utf8((uint16_t *)(void *)(input_buf + field_off), field_len / 2);
         }
 }
 
diff --git a/lib/pdu.c b/lib/pdu.c
index 7144b7f..573dc86 100644
--- a/lib/pdu.c
+++ b/lib/pdu.c
@@ -363,7 +363,7 @@ smb2_set_uint16(struct smb2_iovec *iov, int offset, uint16_t value)
         if (offset + sizeof(uint16_t) > iov->len) {
                 return -1;
         }
-        *(uint16_t *)(iov->buf + offset) = htole16(value);
+        *(uint16_t *)(void *)(iov->buf + offset) = htole16(value);
         return 0;
 }
 
@@ -373,7 +373,7 @@ smb2_set_uint32(struct smb2_iovec *iov, int offset, uint32_t value)
         if (offset + sizeof(uint32_t) > iov->len) {
                 return -1;
         }
-        *(uint32_t *)(iov->buf + offset) = htole32(value);
+        *(uint32_t *)(void *)(iov->buf + offset) = htole32(value);
         return 0;
 }
 
diff --git a/lib/smb2-cmd-create.c b/lib/smb2-cmd-create.c
index 9748634..4991ed8 100644
--- a/lib/smb2-cmd-create.c
+++ b/lib/smb2-cmd-create.c
@@ -450,7 +450,7 @@ smb2_process_create_request_variable(struct smb2_context *smb2,
 
         req->name = NULL;
         if (req->name_length > 0) {
-                req->name = smb2_utf16_to_utf8((const uint16_t*)iov->buf, req->name_length / 2);
+                req->name = smb2_utf16_to_utf8((const uint16_t *)(void *)iov->buf, req->name_length / 2);
                 if (req->name) {
                         name_byte_len = strlen(req->name) + 1;
                         ptr = smb2_alloc_init(smb2, name_byte_len);
diff --git a/lib/smb2-cmd-negotiate.c b/lib/smb2-cmd-negotiate.c
index e4eeee1..190a227 100644
--- a/lib/smb2-cmd-negotiate.c
+++ b/lib/smb2-cmd-negotiate.c
@@ -531,7 +531,7 @@ smb2_parse_netname_request_context(struct smb2_context *smb2,
         char *client;
 
         memcpy(netname, iov->buf + offset, len);
-        client = discard_const(smb2_utf16_to_utf8((uint16_t *)netname, len));
+        client = discard_const(smb2_utf16_to_utf8((uint16_t *)(void *)netname, len));
         free(client);
         return 0;
 }
diff --git a/lib/smb2-cmd-query-directory.c b/lib/smb2-cmd-query-directory.c
index 3dbd2f4..31b5002 100644
--- a/lib/smb2-cmd-query-directory.c
+++ b/lib/smb2-cmd-query-directory.c
@@ -82,7 +82,7 @@ smb2_decode_fileidfulldirectoryinformation(
         smb2_get_uint32(vec, 64, &fs->ea_size);
         smb2_get_uint64(vec, 72, &fs->file_id);
 
-        fs->name = smb2_utf16_to_utf8((uint16_t *)&vec->buf[80], name_len / 2);
+        fs->name = smb2_utf16_to_utf8((uint16_t *)(void *)&vec->buf[80], name_len / 2);
 
         smb2_get_uint64(vec, 8, &t);
         smb2_win_to_timeval(t, &fs->creation_time);
@@ -226,7 +226,7 @@ smb2_encode_query_directory_reply(struct smb2_context *smb2,
                         in_offset = 0;
                         in_remain = fslen;
                         do {
-                                fs = (struct smb2_fileidbothdirectoryinformation*)(rep->output_buffer + in_offset);
+                                fs = (struct smb2_fileidbothdirectoryinformation*)(void *)(rep->output_buffer + in_offset);
                                 fname_len = 0;
                                 if (fs->name && fs->name[0]) {
                                         name = smb2_utf8_to_utf16(fs->name);
@@ -290,7 +290,7 @@ smb2_encode_query_directory_reply(struct smb2_context *smb2,
         else {
 
                 do {
-                        fs = (struct smb2_fileidbothdirectoryinformation*)(rep->output_buffer + in_offset);
+                        fs = (struct smb2_fileidbothdirectoryinformation*)(void *)(rep->output_buffer + in_offset);
                         fname_len = 0;
                         if (fs->name && fs->name[0]) {
                                 name = smb2_utf8_to_utf16(fs->name);
@@ -543,7 +543,7 @@ smb2_process_query_directory_request_variable(struct smb2_context *smb2,
         int name_byte_len;
 
         if (req->file_name_length > 0) {
-                req->name = smb2_utf16_to_utf8((uint16_t*)&iov->buf[IOVREQ_OFFSET], req->file_name_length / 2);
+                req->name = smb2_utf16_to_utf8((uint16_t*)(void *)&iov->buf[IOVREQ_OFFSET], req->file_name_length / 2);
                 if (req->name) {
                         name_byte_len = strlen(req->name) + 1;
                         ptr = smb2_alloc_init(smb2, name_byte_len);
diff --git a/lib/smb2-cmd-tree-connect.c b/lib/smb2-cmd-tree-connect.c
index 15d5b14..a4846a7 100644
--- a/lib/smb2-cmd-tree-connect.c
+++ b/lib/smb2-cmd-tree-connect.c
@@ -260,7 +260,7 @@ smb2_process_tree_connect_request_variable(struct smb2_context *smb2,
         struct smb2_tree_connect_request *req = (struct smb2_tree_connect_request*)pdu->payload;
         struct smb2_iovec *iov = &smb2->in.iov[smb2->in.niov - 1];
 
-        req->path = (uint16_t*)iov->buf;
+        req->path = (uint16_t*)(void *)iov->buf;
         return 0;
 }
 
diff --git a/lib/smb2-data-file-info.c b/lib/smb2-data-file-info.c
index 7b921ff..e12a84e 100644
--- a/lib/smb2-data-file-info.c
+++ b/lib/smb2-data-file-info.c
@@ -199,7 +199,7 @@ smb2_decode_file_all_info(struct smb2_context *smb2,
         smb2_get_uint32(vec, 96, &name_len);
 
         if (name_len > 0) {
-                name = smb2_utf16_to_utf8((uint16_t *)&vec->buf[100], name_len / 2);
+                name = smb2_utf16_to_utf8((uint16_t *)(void *)&vec->buf[100], name_len / 2);
                 fs->name = smb2_alloc_data(smb2, memctx, strlen(name) + 1);
                 if (fs->name == NULL) {
                         free(discard_const(name));
@@ -249,7 +249,7 @@ smb2_encode_file_all_info(struct smb2_context *smb2,
                 if (name) {
                         name_len = 2 * name->len;
                         smb2_set_uint32(vec, 96, name_len);
-                        memcpy((uint16_t *)&vec->buf[100], name->val, name_len);
+                        memcpy((uint16_t *)(void *)&vec->buf[100], name->val, name_len);
                         free(name);
                         return 100 + name_len;
                 } else {
diff --git a/lib/smb2-data-filesystem-info.c b/lib/smb2-data-filesystem-info.c
index 962437f..1de010a 100644
--- a/lib/smb2-data-filesystem-info.c
+++ b/lib/smb2-data-filesystem-info.c
@@ -68,7 +68,7 @@ smb2_decode_file_fs_volume_info(struct smb2_context *smb2,
         smb2_get_uint32(vec, 12, &fs->volume_label_length);
         smb2_get_uint8(vec,  16, &fs->supports_objects);
         smb2_get_uint8(vec,  17, &fs->reserved);
-        name = smb2_utf16_to_utf8((uint16_t *)&vec->buf[18],
+        name = smb2_utf16_to_utf8((uint16_t *)(void *)&vec->buf[18],
                             fs->volume_label_length / 2);
         fs->volume_label = smb2_alloc_data(smb2, memctx, strlen(name) + 1);
         if (fs->volume_label == NULL) {
@@ -186,7 +186,7 @@ smb2_decode_file_fs_attribute_info(struct smb2_context *smb2,
         smb2_get_uint32(vec, 8, &name_len);
 
         if (name_len > 0) {
-                name = smb2_utf16_to_utf8((uint16_t*)&vec->buf[12], name_len / 2);
+                name = smb2_utf16_to_utf8((uint16_t*)(void *)&vec->buf[12], name_len / 2);
                 if (!name) {
 
                         return -1;
diff --git a/lib/smb2-data-reparse-point.c b/lib/smb2-data-reparse-point.c
index b53c711..13e5abf 100644
--- a/lib/smb2-data-reparse-point.c
+++ b/lib/smb2-data-reparse-point.c
@@ -85,7 +85,7 @@ smb2_decode_reparse_data_buffer(struct smb2_context *smb2,
                         return -1;
                 }
 
-                tmp = smb2_utf16_to_utf8((uint16_t *)(&vec->buf[suboffset + 20]),
+                tmp = smb2_utf16_to_utf8((uint16_t *)(void *)(&vec->buf[suboffset + 20]),
                                    sublen / 2);
                 rp->symlink.subname = smb2_alloc_data(smb2, rp,
                                                       strlen(tmp) + 1);
@@ -101,7 +101,7 @@ smb2_decode_reparse_data_buffer(struct smb2_context *smb2,
                 if (printoffset + printlen + 12 > rp->reparse_data_length) {
                         return -1;
                 }
-                tmp = smb2_utf16_to_utf8((uint16_t *)(&vec->buf[printoffset + 20]),
+                tmp = smb2_utf16_to_utf8((uint16_t *)(void *)(&vec->buf[printoffset + 20]),
                                    printlen / 2);
                 rp->symlink.printname = smb2_alloc_data(smb2, rp,
                                                         strlen(tmp) + 1);
-- 
2.47.2

