From c4bb6abc2b61390468a6f68907d47dafaff407dd Mon Sep 17 00:00:00 2001 From: Ben Gras Date: Thu, 22 Jul 2010 22:35:44 +0000 Subject: [PATCH] vsprintf: fix special yet useful case for vsprintf where n < 1. reported by jaldhar. --- lib/libc/stdio/vsprintf.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/libc/stdio/vsprintf.c b/lib/libc/stdio/vsprintf.c index 7f0cc2f9e..38b4964f3 100644 --- a/lib/libc/stdio/vsprintf.c +++ b/lib/libc/stdio/vsprintf.c @@ -21,8 +21,10 @@ vsnprintf(char *s, size_t n, const char *format, va_list arg) tmp_stream._count = n-1; retval = _doprnt(format, arg, &tmp_stream); - tmp_stream._count = 1; - (void) putc('\0',&tmp_stream); + if(n > 0) { + tmp_stream._count = 1; + (void) putc('\0',&tmp_stream); + } return retval; } -- 2.44.0