This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

snprintf implementation broken

Hi,

It seems that snprintf is broken in MDK 4.72 and Microlib.

My intention was to use it to pre-calculate the size of the formatted output, and thus I gave it a NULL-pointer and a buffer size of 0, like so:

n = snprintf(NULL, 0, "test");

According to the standard, this is allowable, but instead it crashes my application (it tries to write to the NULL-pointer).

In short, it always tries to write to the buffer, no matter if the length is zero or the buffer is a NULL-pointer (or both).

I haven't seen if it behaves properly with the standard library, because I prefer Microlib for size.

Parents Reply Children