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 b3977bbe29fea28adaeadf76956ed592a35b9b90
Author: Marco Casaroli <[email protected]>
AuthorDate: Thu Nov 5 06:51:56 2026 +0100

    libs/libc/stream: Count the output of %pV and %pB.
    
    %pV and %pB did not add their output to the return value.  vasprintf() has
    an assertion that the return value is the same as the count of the null
    stream, so asprintf() with %pV crashes when the assertions are on.  The
    return value of the other functions was too small.
    
    Add the output of these conversions to the total.
    
    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 | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/libs/libc/stream/lib_libvsprintf.c 
b/libs/libc/stream/lib_libvsprintf.c
index effd6637244..6a56c94f563 100644
--- a/libs/libc/stream/lib_libvsprintf.c
+++ b/libs/libc/stream/lib_libvsprintf.c
@@ -1345,7 +1345,8 @@ str_lpad:
                       {
                         FAR struct va_format *vaf = (FAR void *)(uintptr_t)x;
 
-                        lib_bsprintf(stream, vaf->fmt, vaf->va);
+                        total_len += lib_bsprintf(stream, vaf->fmt,
+                                                  vaf->va);
                         continue;
                       }
 
@@ -1356,10 +1357,11 @@ str_lpad:
                         va_list copy;
 
                         va_copy(copy, *vaf->va);
-                        lib_vsprintf(stream, vaf->fmt, copy);
+                        total_len += lib_vsprintf(stream, vaf->fmt, copy);
                         va_end(copy);
 #  else
-                        lib_vsprintf(stream, vaf->fmt, *vaf->va);
+                        total_len += lib_vsprintf(stream, vaf->fmt,
+                                                  *vaf->va);
 #  endif
                         continue;
                       }

Reply via email to