tiny-printf: emit \0 as %c
authorAlexander Sverdlin <alexander.sverdlin@siemens.com>
Thu, 20 Feb 2025 12:49:07 +0000 (13:49 +0100)
committerTom Rini <trini@konsulko.com>
Mon, 3 Mar 2025 20:24:45 +0000 (14:24 -0600)
commit1bc125becaa5e612923a9cfa1ec8e9f0b88ac28e
tree375864c505446e6299520d66566d60eea514e423
parent0928e3cc719711d677083982de5dbb68da0a1470
tiny-printf: emit \0 as %c

The current code has a problematic corner case with formar "%c" and
0 as parameter. The proper zero byte is being emitted into digit buffer
but the final copy into outstr expects null-terminated string and doesn't
copy the required \0 byte. This has lead to malformed TFTP packets, refer
to tftp_send() which relies on %c to generate multiple zero-terminated
strings in one buffer.

Introduce a variable to force the copy of one character in this case.
The new behaviour is consistent with non-tiny implementation.

Reported-by: Chintan Vankar <c-vankar@ti.com>
Signed-off-by: Alexander Sverdlin <alexander.sverdlin@siemens.com>
lib/tiny-printf.c