1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
From: Ronnie Sahlberg <ronniesahlberg@gmail.com>
Subject: [PATCH] Fix compiler warning about "cast increases required
alignment"
Origin: upstream, https://github.com/sahlberg/libsmb2/commit/66b098787213cda14d8fbf6e346517df2bb1fe7e
Bug: https://github.com/sahlberg/libsmb2/issues/408
Last-Update: 2024-04-03
Some ISA, like ARMv6, do not support unaligned memory accesses.
The cast here technically convert a the pointer target from a char to
another pointer.
However, as the buf field (char) is laid out after a pointer in the
structure definition, the alignment for buf is forced to the same
alignment as a pointer.
Thus the issue with unaligned access can not happen and the workaround
by re-casting the pointer via void * is safe.
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
---
lib/alloc.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/alloc.c b/lib/alloc.c
index bd5c8aa..2c2b7be 100644
--- a/lib/alloc.c
+++ b/lib/alloc.c
@@ -113,7 +113,7 @@ smb2_alloc_data(struct smb2_context *smb2, void *memctx, size_t size)
}
#ifndef _MSC_VER
- hdr = container_of(memctx, struct smb2_alloc_header, buf);
+ hdr = (struct smb2_alloc_header *)(void *)container_of(memctx, struct smb2_alloc_header, buf);
#else
{
const char* __mptr = memctx;
@@ -138,7 +138,7 @@ smb2_free_data(struct smb2_context *smb2, void *ptr)
}
#ifndef _MSC_VER
- hdr = container_of(ptr, struct smb2_alloc_header, buf);
+ hdr = (struct smb2_alloc_header *)(void *)container_of(ptr, struct smb2_alloc_header, buf);
#else
{
const char* __mptr = ptr;
--
2.47.2
|