-
Notifications
You must be signed in to change notification settings - Fork 62
Fix: Packed attribute missing for FF_Part_t causing buggy memcpy and alignment issues #77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Hi @Adithya65, |
|
Thank you for this PR. /* Store this partition for the caller */
FF_Part_t * p = &pPartsFound->pxPartitions[ pPartsFound->iCount++ ];
/* Copy the whole structure */
memcpy( p, pxPartitions + xPartNr, sizeof( *p ) );
/* and make LBA absolute to sector-0. */
p->ulStartLBA += ulThisSector;
p->bIsExtended = pdTRUE;For instance, I would rather copy the bytes in an alignment-safe loop. That avoids that the proposed change will affect a lot of other code. |
|
Sorry, transforming from bitfields to - ucActive : 8, /* FF_FAT_PTBL_ACTIVE */
- ucPartitionID : 8, /* FF_FAT_PTBL_ID */
- bIsExtended : 1;
+ uint8_t ucActive; /* FF_FAT_PTBL_ACTIVE */
+ uint8_t ucPartitionID; /* FF_FAT_PTBL_ID */
+ uint8_t bIsExtended;
+ uint8_t bIsUnused; /* Byte added to make the length a multiple of 32 byte. */and without the packed attribute. |
|
Hi @htibosch , I will update those changes.Do you want me to raise a fresh PR. |
|
This is ff_ioman,c with some minor format changes: ff_ioman.zip -} /* extern "C" */
+ } /* extern "C" */
#endif
#endif /* ifndef _FF_IOMAN_H_ */
+I thought we had a tool that source formats a file on github directly? Maybe only in the +TCP repo? The nice thing of this filler byte is that it can be assigned a new meaning/function without the risk of changing the size of the struct. |
htibosch
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @Adithya65 for this PR. Thanks @ActoryOu for the suggestion to turn the bitfields into uint8_t fields.
I approve it.
Fix: Packed attribute missing for FF_Part_t causing buggy memcpy and alignment issues
Description
The structure
FF_Part_twas used withmemcpyto copy partition data (pxPartitions + xPartNrintop) in ff_ioman.c, but it contains bitfields:typedef struct _SPart
{
uint32_t ulStartLBA;
uint32_t ulSectorCount;
uint32_t ucActive : 8,
ucPartitionID : 8,
bIsExtended : 1;
} FF_Part_t;
Test Steps
This is a general fix; no additional tests are required.
Checklist:
Related Issue
None opened
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.