You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by pk...@apache.org on 2022/11/27 21:59:29 UTC
[nuttx] 03/04: libc/stdio: Don't count the output length repeatly in vsprintf_internal
This is an automated email from the ASF dual-hosted git repository.
pkarashchenko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 7568a0df22ab80fac2ba458c9ee4c27379f53367
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sat Nov 26 02:13:34 2022 +0800
libc/stdio: Don't count the output length repeatly in vsprintf_internal
let's reuse the counting from lib_outstream_s::nput instead
Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
libs/libc/stdio/lib_libvsprintf.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/libs/libc/stdio/lib_libvsprintf.c b/libs/libc/stdio/lib_libvsprintf.c
index 28657b7679..9fb6c9117d 100644
--- a/libs/libc/stdio/lib_libvsprintf.c
+++ b/libs/libc/stdio/lib_libvsprintf.c
@@ -73,7 +73,7 @@
# undef putc
#endif
-#define putc(c,stream) (total_len++, (stream)->put(stream, c))
+#define putc(c,stream) (stream)->put(stream, c)
/* Order is relevant here and matches order in format string */
@@ -201,9 +201,9 @@ static int vsprintf_internal(FAR struct lib_outstream_s *stream,
FAR const char *pnt;
size_t size;
unsigned char len;
- int total_len = 0;
#ifdef CONFIG_LIBC_NUMBERED_ARGS
+ int total_len = 0;
int argnumber = 0;
#endif
@@ -1357,7 +1357,11 @@ tail:
}
ret:
- return total_len;
+#ifdef CONFIG_LIBC_NUMBERED_ARGS
+ return stream ? stream->nput : total_len;
+#else
+ return stream->nput;
+#endif
}
/****************************************************************************