[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT PATCH] lib/nolibc: Fix vsnprintf when size is zero



Modified PCHAR macro so that it evaluates its parameter and updates
their values every time. Without this, when size is zero, vsnprintf
blocks in an infinite loop whenever the format string contains '%d'.

Signed-off-by: Razvan Rotaru <razvanrtr@xxxxxxxxxxx>
---
 lib/nolibc/stdio.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/nolibc/stdio.c b/lib/nolibc/stdio.c
index 7e3d368..c2e9f59 100644
--- a/lib/nolibc/stdio.c
+++ b/lib/nolibc/stdio.c
@@ -101,8 +101,9 @@ int vsnprintf(char *str, size_t size, const char *fmt, 
va_list ap)
 {
 #define PCHAR(c)                                                               
\
        {                                                                      \
+               int cc = c;                                                    \
                if (size >= 2) {                                               \
-                       *str++ = c;                                            \
+                       *str++ = cc;                                           \
                        size--;                                                \
                }                                                              \
                retval++;                                                      \
-- 
2.11.0


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.