Skip to content

Fix some compiler warning about unaligned access - #197

Open
mhei wants to merge 2 commits into
qca:masterfrom
mhei:bugfix/unaligned-access
Open

Fix some compiler warning about unaligned access#197
mhei wants to merge 2 commits into
qca:masterfrom
mhei:bugfix/unaligned-access

Conversation

@mhei

@mhei mhei commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

This PR reworks some access to members in packed structs.

@n1000

n1000 commented Sep 7, 2026

Copy link
Copy Markdown
Member

Thanks @mhei for these changes. I added a couple minor comments in the review. At least on GCC 14.2 the compiler is smart enough to not warn about taking the address of a packed structure member if it is immediately converted into a void * or uint8_t *.

mhei added 2 commits September 8, 2026 13:44
Serialize variable-length VLAN items through a byte buffer
instead of taking an aligned struct pointer to a packed
message member.

GCC does not warn when a packed member address is immediately
converted to void * or uint8_t *, and that conversion is safe
while the address remains byte-oriented.
Merely casting the original struct item pointer through void *,
however, would only hide the warning: the following uint16_t
member stores could still be unaligned.

Use a direct uint8_t * conversion for locating the output
and use memcpy to serialize the multi-byte fields without
aligned typed accesses.

Signed-off-by: Michael Heimpold <mhei@heimpold.de>
Populate the slave bitmap in aligned storage before copying
it into the packed MDU traffic statistics request.

GCC does not warn when the packed member is passed directly
to memcpy because its address is converted to void *, and
this is safe for a byte-wise copy.
Passing the same address through void * to set32bitmap() would
only hide the warning: the function ultimately accesses it as
uint32_t *, while the bitmap starts at an address that is not
guaranteed to have the required alignment.

So use an aligned temporary variable for set32bitmap() and
use the packed member directly as the memcpy destination.

Signed-off-by: Michael Heimpold <mhei@heimpold.de>
@mhei

mhei commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

I added a couple minor comments in the review

Oh, it seems that I dont see the comments already...

At least on GCC 14.2 the compiler is smart enough...

This is a good point, thanks for pointing out. This makes the patch a little bit simpler and thus easier to read, but the main problem persists. I will force-push a revised version and elaborate in the commit messages...

@mhei
mhei force-pushed the bugfix/unaligned-access branch from bee6884 to 4a14b41 Compare September 8, 2026 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants