Skip to content
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

Address of packed member #121

Open
JVKran opened this issue Jun 28, 2022 · 1 comment
Open

Address of packed member #121

JVKran opened this issue Jun 28, 2022 · 1 comment
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project

Comments

@JVKran
Copy link

JVKran commented Jun 28, 2022

Hi there!

Hope you're doing great. We're stumbling upon a compiler warning about taking an address of a packed member in this library. We think we're facing an issue with this in our application. Without going much further in said application (which I can not share), I'll now give a more detailed description of the warning.

When compiling any application with this library included and the Adafruit nRF52832 Feather selected as board, one is presented with the warning underneath.

C:\Program Files (x86)\Arduino\libraries\SD\src\utility\SdFile.cpp: In member function 'uint8_t SdFile::open(SdFile*, const char*, uint8_t)':
C:\Program Files (x86)\Arduino\libraries\SD\src\utility\SdFile.cpp:532:15: warning: taking address of packed member of 'directoryEntry' may result in an unaligned pointer value [-Waddress-of-packed-member]
  532 |     dateTime_(&p->creationDate, &p->creationTime);
      |               ^~~~~~~~~~~~~~~~
C:\Program Files (x86)\Arduino\libraries\SD\src\utility\SdFile.cpp:532:15: warning: taking address of packed member of 'directoryEntry' may result in an unaligned pointer value [-Waddress-of-packed-member]
C:\Program Files (x86)\Arduino\libraries\SD\src\utility\SdFile.cpp:532:33: warning: taking address of packed member of 'directoryEntry' may result in an unaligned pointer value [-Waddress-of-packed-member]
  532 |     dateTime_(&p->creationDate, &p->creationTime);
      |                                 ^~~~~~~~~~~~~~~~
C:\Program Files (x86)\Arduino\libraries\SD\src\utility\SdFile.cpp:532:33: warning: taking address of packed member of 'directoryEntry' may result in an unaligned pointer value [-Waddress-of-packed-member]
C:\Program Files (x86)\Arduino\libraries\SD\src\utility\SdFile.cpp: In member function 'uint8_t SdFile::sync(uint8_t)':
C:\Program Files (x86)\Arduino\libraries\SD\src\utility\SdFile.cpp:1155:17: warning: taking address of packed member of 'directoryEntry' may result in an unaligned pointer value [-Waddress-of-packed-member]
 1155 |       dateTime_(&d->lastWriteDate, &d->lastWriteTime);
      |                 ^~~~~~~~~~~~~~~~~
C:\Program Files (x86)\Arduino\libraries\SD\src\utility\SdFile.cpp:1155:17: warning: taking address of packed member of 'directoryEntry' may result in an unaligned pointer value [-Waddress-of-packed-member]
C:\Program Files (x86)\Arduino\libraries\SD\src\utility\SdFile.cpp:1155:36: warning: taking address of packed member of 'directoryEntry' may result in an unaligned pointer value [-Waddress-of-packed-member]
 1155 |       dateTime_(&d->lastWriteDate, &d->lastWriteTime);
      |                                    ^~~~~~~~~~~~~~~~~
C:\Program Files (x86)\Arduino\libraries\SD\src\utility\SdFile.cpp:1155:36: warning: taking address of packed member of 'directoryEntry' may result in an unaligned pointer value [-Waddress-of-packed-member]

I would've opened a pull-request if I new what the reason is for it being a packed member in the first place. I don't see any obvious reasons as to why you'd want that in this case; not every byte counts in this situation I suppose?

I propose to make the struct not packed.

Kind regards,

Jochem

@per1234 per1234 added type: imperfection Perceived defect in any part of project topic: code Related to content of the project itself labels Jun 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

3 participants
@per1234 @JVKran and others