This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new abfdffd879 libc/libvsprintf:fix vsnprintf bug with "%#.0f"
abfdffd879 is described below

commit abfdffd87940c01dd9c6dc97401bfb2e4d47235c
Author: Sunny <[email protected]>
AuthorDate: Tue Jul 4 09:37:42 2023 +0000

    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 <[email protected]>
---
 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
             {

Reply via email to