diff options
Diffstat (limited to 'lib/libc/stdio/vsnprintf.c')
-rw-r--r-- | lib/libc/stdio/vsnprintf.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/libc/stdio/vsnprintf.c b/lib/libc/stdio/vsnprintf.c index 85e456290b2..b965b146442 100644 --- a/lib/libc/stdio/vsnprintf.c +++ b/lib/libc/stdio/vsnprintf.c @@ -35,9 +35,10 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: vsnprintf.c,v 1.3 1997/11/29 19:28:30 millert Exp $"; +static char rcsid[] = "$OpenBSD: vsnprintf.c,v 1.4 1998/01/12 06:14:32 millert Exp $"; #endif /* LIBC_SCCS and not lint */ +#include <limits.h> #include <stdio.h> int @@ -50,12 +51,15 @@ vsnprintf(str, n, fmt, ap) int ret; FILE f; - if ((int)n < 1) - return (-1); + /* While snprintf(3) specifies size_t stdio uses an int internally */ + if (n > INT_MAX) + n = INT_MAX; + f._file = -1; f._flags = __SWR | __SSTR; f._bf._base = f._p = (unsigned char *)str; - f._bf._size = f._w = n - 1; + f._bf._size = f._w = n ? n - 1 : 0; ret = vfprintf(&f, fmt, ap); - *f._p = 0; + if (n) + *f._p = '\0'; return (ret); } |