From abfdffd87940c01dd9c6dc97401bfb2e4d47235c Mon Sep 17 00:00:00 2001 From: Sunny Date: Tue, 4 Jul 2023 09:37:42 +0000 Subject: [PATCH] libc/libvsprintf:fix vsnprintf bug with "%#.0f" With double value=3.141593 initialized in va_list ap, such code: vsnprintf(buffer, sizeof(buffer), "%#.0f", ap); expected output string: "3." but real output string: ".3" Signed-off-by: Sunny --- libs/libc/stdio/lib_libvsprintf.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libs/libc/stdio/lib_libvsprintf.c b/libs/libc/stdio/lib_libvsprintf.c index b0f8b74e7f..f3904e505b 100644 --- a/libs/libc/stdio/lib_libvsprintf.c +++ b/libs/libc/stdio/lib_libvsprintf.c @@ -816,11 +816,6 @@ flt_oper: if (--n < -prec) { - if ((flags & FL_ALT) != 0 && n == -1) - { - stream_putc('.', stream); - } - break; } @@ -835,6 +830,11 @@ flt_oper: } stream_putc(out, stream); + + if ((flags & FL_ALT) != 0 && n == -1) + { + stream_putc('.', stream); + } } else {