summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>1998-07-27 02:28:29 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>1998-07-27 02:28:29 +0000
commitd3d6a4e5860715c18435ff8da6670bc7f5caf695 (patch)
tree20fdf74c2f5c8f6bd900aa430ad75199c3a62041 /lib
parentf07bd065d9ebe2c7f630bab745a468d7def06a1b (diff)
Use a single character buffer for the size==0 case. Stdio internals do not deal correctly with zero size buffer and NULL pointer. torek@bsdi.com
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/stdio/vsnprintf.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/libc/stdio/vsnprintf.c b/lib/libc/stdio/vsnprintf.c
index b965b146442..3fe0bb07af9 100644
--- a/lib/libc/stdio/vsnprintf.c
+++ b/lib/libc/stdio/vsnprintf.c
@@ -35,7 +35,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: vsnprintf.c,v 1.4 1998/01/12 06:14:32 millert Exp $";
+static char rcsid[] = "$OpenBSD: vsnprintf.c,v 1.5 1998/07/27 02:28:28 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#include <limits.h>
@@ -49,17 +49,22 @@ vsnprintf(str, n, fmt, ap)
_BSD_VA_LIST_ ap;
{
int ret;
+ char dummy;
FILE f;
/* While snprintf(3) specifies size_t stdio uses an int internally */
if (n > INT_MAX)
n = INT_MAX;
+ /* Stdio internals do not deal correctly with zero length buffer */
+ if (n == 0) {
+ str = &dummy;
+ n = 1;
+ }
f._file = -1;
f._flags = __SWR | __SSTR;
f._bf._base = f._p = (unsigned char *)str;
- f._bf._size = f._w = n ? n - 1 : 0;
+ f._bf._size = f._w = n - 1;
ret = vfprintf(&f, fmt, ap);
- if (n)
- *f._p = '\0';
+ *f._p = 0;
return (ret);
}