FIX: Mark uart parameters and sp as non-const pointers.#611
FIX: Mark uart parameters and sp as non-const pointers.#611micolous wants to merge 1 commit intoProxmark:masterfrom
sp as non-const pointers.#611Conversation
Internally, the `uart_*` implementations treat their parameter as a pointer. While the C compiler technically doesn't have a way to enforce that you're not modifying memory referred to by a `const` pointer, there's not a good reason to prohibit an implementation of `uart` from doing so, if it makes sense for that platform or environment. PM3 also fairly consistently casts the value to a non-const pointer anyway. This also explicitly sets `sp` to NULL, which should cause an uninitialized use of `sp` to dereference a null pointer (generally crashing with a segfault, as the program tries to reference unmapped memory), rather than reading some nearby program memory (and have undefined behaviour). That will make it very obvious in a debugger, when something has gone wrong. For example: ``` * thread iceman1001#1: tid = 32727, 0x0000555555556e1b flasher`uart_send(sp=0x0000000000000000, pbtTx="", szTxLen=544) + 123 at uart_posix.c:204, name = 'flasher', stop reason = signal SIGSEGV: invalid address (fault address: 0x0) frame #0: 0x0000555555556e1b flasher`uart_send(sp=0x0000000000000000, pbtTx="", szTxLen=544) + 123 at uart_posix.c:204 ``` This should address a number of compiler warnings on uart files.
|
I am not sure about what you want to achieve here. What kind of warnings do you get? Please don't expect that the upstream repository always suits your needs. Someone may fiddle with the comms or uart functions in the future and will have no idea that this would impact your downstream repository. You already have your own However, if this are just small modifications then add some |
|
I got mixed up because while I did not intend it to be a This "issue" had been bothering me a while, and I was honestly surprised you hadn't found it yet. But it's good to get closure. As I have unintentionally made it worse with this PR, I'm retracting this. Thanks! |
Internally, the
uart_*implementations treat their parameter as a pointer.While the C compiler technically doesn't have a way to enforce that you're not modifying memory referred to by a
constpointer, there's not a good reason to prohibit an implementation ofuartfrom doing so, if it makes sense for that platform or environment.PM3 also fairly consistently casts the value to a non-const pointer anyway.
This also explicitly sets
spto NULL, which should cause an uninitialized use ofspto dereference a null pointer (generally crashing with a segfault, as the program tries to reference unmapped memory), rather than reading some nearby program memory (and have undefined behaviour).That will make it very obvious in a debugger, when something has gone wrong. For example:
This should address a number of compiler warnings on uart files.