Skip to content

Undefined behavior in pkg/semtech-loramac/contrib/ #14667

@maribu

Description

@maribu

Description

The C standard takes Harvard Architectures into account, for which program and data memory are distinct address spaces. This also means that they can have different address sizes, which e.g. for the AVR platform is the case: RAM addresses are always 16 bit wide and ROM addresses can be 22 bit wide (look up the program counter size).

As a result, the C standard forbids to cast function pointers (ROM address) to data pointers (RAM addresses). (This includes that void * pointers cannot be used to store a function address.)

Steps to reproduce the issue

Check this chunks of code:

void TimerStart(TimerEvent_t *obj)
{
obj->running = 1;
xtimer_t *timer = &(obj->dev);
msg_t *msg = &(obj->msg);
msg->type = MSG_TYPE_MAC_TIMEOUT;
msg->content.ptr = obj->cb;
xtimer_set_msg(timer, obj->timeout, msg, semtech_loramac_pid);
}

case MSG_TYPE_MAC_TIMEOUT:
{
DEBUG("[semtech-loramac] MAC timer timeout\n");
void (*callback)(void) = msg.content.ptr;
callback();
break;
}

Expected results

No cast from function pointer to data pointer and vice versa.

Actual results

A cast from function pointer to data pointer and the other direction is present.

Versions

Current master.


Discussion started in #14663

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: LoRaArea: LoRa radio supportArea: networkArea: NetworkingType: bugThe issue reports a bug / The PR fixes a bug (including spelling errors)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions