-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Undefined behavior in pkg/semtech-loramac/contrib/ #14667
Description
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:
RIOT/pkg/semtech-loramac/contrib/semtech_loramac_timer.c
Lines 41 to 49 in 7e4b3d0
| 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); | |
| } |
RIOT/pkg/semtech-loramac/contrib/semtech_loramac.c
Lines 609 to 615 in 7e4b3d0
| 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