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

WARNING: taking address of packed member of 'directoryEntry' may result in an unaligned pointer value #157

Open
brightproject opened this issue Aug 12, 2024 · 0 comments
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project

Comments

@brightproject
Copy link

My platformio.ini

[platformio]
description = BNO055
default_envs = genericSTM32F411CE

[env:genericSTM32F401CE]
platform = ststm32

[env:genericSTM32F411CE]
platform = ststm32
platform_packages = platformio/framework-arduinoststm32@^4.20801.240802

board = blackpill_f411ce
framework = arduino

monitor_speed = 230400
monitor_port = COM6

; debug_tool = stlink
; upload_protocol = dfu
; upload_protocol = stlink

lib_deps =
adafruit/Adafruit BNO055@^1.6.3

; change MCU frequency
board_build.f_cpu = 100000000L

When compiling code with library

name=SD
version=1.3.0

I received warnings:

SdFile.cpp:1175:17: warning: taking address of packed member of 'directoryEntry' may result in an unaligned pointer value [-Waddress-of-packed-member]
 1175 |       dateTime_(&d->lastWriteDate, &d->lastWriteTime);

Replaced these functions

if (dateTime_) {

with

  // set timestamps
if (dateTime_) {
    // call user function using temporary variables for safety
    uint16_t creationDate = p->creationDate;
    uint16_t creationTime = p->creationTime;
    dateTime_(&creationDate, &creationTime);

   // After getting new values ​​from dateTime_, you can assign them back if needed.
    p->creationDate = creationDate;
    p->creationTime = creationTime;
} else {
    // use default date/time
    p->creationDate = FAT_DEFAULT_DATE;
    p->creationTime = FAT_DEFAULT_TIME;
}

p->lastAccessDate = p->creationDate;
p->lastWriteDate = p->creationDate;
p->lastWriteTime = p->creationTime;

and

if (dateTime_) {

with

// set modify time if user supplied a callback date/time function
if (dateTime_) {
// Create temporary variables to safely call dateTime_
uint16_t lastWriteDate = d->lastWriteDate;
uint16_t lastWriteTime = d->lastWriteTime;

// Call the function with temporary variables
dateTime_(&lastWriteDate, &lastWriteTime);

// If necessary, save updated values ​​back to the structure
d->lastWriteDate = lastWriteDate;
d->lastWriteTime = lastWriteTime;

// Update lastAccessDate based on lastWriteDate d->lastAccessDate = d->lastWriteDate;
}

After these changes, yellow warnings during compilation disappeared.

@per1234 per1234 added type: imperfection Perceived defect in any part of project topic: code Related to content of the project itself labels Aug 12, 2024
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

2 participants