-
-
Notifications
You must be signed in to change notification settings - Fork 209
Description
@thirtytwobits says:
the
CanardTransferpayload isconst void*but is <...> used to free the payload when you are done with it. This leads toconst_cast<void*>(transfer->payload)in C++ which is not something you ever want to see.constis part of the API so if you violate the constness you are, technically, entering undefined behaviour.
to which I say:
This is a known issue, yes: https://github.com/UAVCAN/libcanard/blob/2a116170285fb47fcaae150ad21c2ccde0756a5f/libcanard/canard.h#L251-L252
The reason the deallocation function accepts a mutablevoid*is because thefree()from the standard library is defined this way.
We could make itconst void*but then if you are using the standard heap or pretty much any other heap manager implemented in C (like o1heap), you will have to cast away your const anyway before calling the deallocation function.
Makingo1heapFree()accept a const void would require it to cast away the const also because it has to mutate the returned memory fragment.
Fixing this requires breaking API changes so it is postponed until v2.0.