Skip to content

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

Open
@brightproject

Description

@brightproject

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: codeRelated to content of the project itselftype: imperfectionPerceived defect in any part of project

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions