Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Potential bug in example code #65

Open
SebastianSchildt opened this issue Jan 2, 2025 · 1 comment
Open

Potential bug in example code #65

SebastianSchildt opened this issue Jan 2, 2025 · 1 comment
Assignees

Comments

@SebastianSchildt
Copy link
Collaborator

There lurks a potentially nasty bug in the example in the toplevel Readme

Open1722/README.md

Lines 148 to 149 in 7fe06a3

Avtp_Lin_t lin;
uint8_t linPayload[LIN_PAYLOAD_LEN];

C standard does not guarantee that uint8_t linPayload[LIN_PAYLOAD_LEN]; follows in memory after Avtp_Lin_t lin; there might be gaps in between due to alignment. Thus the memcpy in the end may copy an invalid frame.

I think either we change the example using a more robust pattern, or at least warn about this (there are some non-standard tags in some compilers to force it to create packed structs)

@adriaan-niess
Copy link
Member

My proposal would be to add a __attribute__((packed)) even though it might not be supported by all compilers.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants