This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit b8c51b44d5debe251bf0f93acf3395343879f070 Author: Marco Casaroli <[email protected]> AuthorDate: Thu Nov 5 06:51:56 2026 +0100 libs/libc/stream: Do not read before the buffer for %#.0x of 0. A value of 0 with a precision of 0 has no digits, so c is 0, and the check for a first digit of 0 read buf[-1]. The result was the prefix or none, from the value of that byte. %p with a precision and a NULL has the same problem. With no digits, drop the 0x prefix. %#.0o keeps its "0": the C standard requires it. Part of https://github.com/apache/nuttx/issues/21467 Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]> --- libs/libc/stream/lib_libvsprintf.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libs/libc/stream/lib_libvsprintf.c b/libs/libc/stream/lib_libvsprintf.c index 4e58aa02b7d..effd6637244 100644 --- a/libs/libc/stream/lib_libvsprintf.c +++ b/libs/libc/stream/lib_libvsprintf.c @@ -1451,7 +1451,11 @@ str_lpad: if ((flags & FL_ALT) != 0) { - if (buf[c - 1] == '0') + /* c is 0 for a value of 0 with a precision of 0: then %#o has a + * "0" from the flag, and a hexadecimal value has no prefix. + */ + + if (c == 0 ? (flags & FL_ALTHEX) != 0 : buf[c - 1] == '0') { flags &= ~(FL_ALT | FL_ALTHEX | FL_ALTUPP); }
