mirror of https://github.com/ARMmbed/mbed-os.git
The printf(3) man page says "The functions snprintf() and vsnprintf() do not write more than size bytes (including the terminating null byte ('\0')). If the output was truncated due to this limit, then the return value is the number of characters (excluding the terminating null byte) which would have been written to the final string if enough space had been available." The last part of this spec (returning the number of characters which would have been written to the string if enough space had been available) was not implemented in minimal-printf. This PR changes that by redirecting all the processed characters through the "minimal_printf_putchar" helper function. This function will not write to the buffer if there's no space left, but it will always increment the number of written characters, in order to match the above description. minimal_printf_putchar also contains checks for overflows, so these checks are no longer needed in the rest of the code. Other changes: - In some cases, mbed_minimal_formatted_string didn't put the string terminator in the output buffer. This PR ensures that this always happens. - Fixed a bug in printed hexadecimal numbers introduced by a previous commit. - Added buffer overflow tests for snprintf. |
||
---|---|---|
.. | ||
minimal-printf |