Fix some compiler warning about unaligned access - #197
Open
mhei wants to merge 2 commits into
Open
Conversation
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 |
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>
Contributor
Author
Oh, it seems that I dont see the comments already...
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
force-pushed
the
bugfix/unaligned-access
branch
from
September 8, 2026 11:51
bee6884 to
4a14b41
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR reworks some access to members in packed structs.