in
Normally this warning is triggered due to an inconsistency in how the function is declared.
Is there a prototype of this function somehwere else (like in a header file) that would happen to have a different declaration?
There is also a lot more buffer size checking like
which isn't necessarily a bug because if the destination code has been written right, (...)
This warning usually "just" means that from the format string passed to sprintf(), the worst case could overflow the buffer passed as a first argument.
It's not ultra-clever, but false positives are relatively rare.
Of course, in practice the code may ensure that the worst case is never reached, but software is full of bugs that should never happen, so.
After making sure the buffer is properly sized, one better approach is to use snprintf() and pass the size of the buffer to it. Avoids any potential overflow.
As Youtubers would say: "Stop using sprintf() !"
This one is weird (not my code I should say)
What I don't get is why previous versions didn't complain. I also don't get the double cast - what is it meant to do?
The %x format expects an 'unsigned int' as an argument.
uint32_t is not equivalent to an unsigned int in general (in a portable way). So you get a warning.
The proper C printf formats for stdint integers '(u)intxx_t' are macros of the type 'PRIxyy' that are found in the inttypes.h standard header, so you need to '#include <inttypes.h>'.
In this piece of code, since buffer's pointer base type is uint8_t, the cast (uint8_t) is useless. (I'm assuming the base type of 'buffer' is uint8_t, but is it? If not, then the cast may be warranted.)
The cast (uint32_t) is, strictly speaking, not correct as said above. You should replace it with (unsigned int).
Can it be done without entirely? In your case, yes. You can remove both casts.
But if you wanted your code to compile keeping the two casts as is without warning, you'd need to '#include <inttypes.h>', and use the following format string instead:
" %02" PRIx32