]> Zhao Yanbai Git Server - minix.git/commitdiff
vsprintf: fix special yet useful case for vsprintf where n < 1.
authorBen Gras <ben@minix3.org>
Thu, 22 Jul 2010 22:35:44 +0000 (22:35 +0000)
committerBen Gras <ben@minix3.org>
Thu, 22 Jul 2010 22:35:44 +0000 (22:35 +0000)
reported by jaldhar.

lib/libc/stdio/vsprintf.c

index 7f0cc2f9e784a393601339250309b9fba9f96026..38b4964f385558eb631da1ca6734317e984b7f9d 100644 (file)
@@ -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;
 }