summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/vasprintf.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/stdio/vasprintf.c')
-rw-r--r--lib/libc/stdio/vasprintf.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/libc/stdio/vasprintf.c b/lib/libc/stdio/vasprintf.c
index 98cdb45549f..a5d08509963 100644
--- a/lib/libc/stdio/vasprintf.c
+++ b/lib/libc/stdio/vasprintf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vasprintf.c,v 1.19 2015/12/28 22:08:18 mmcc Exp $ */
+/* $OpenBSD: vasprintf.c,v 1.20 2017/03/14 16:46:05 millert Exp $ */
/*
* Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -22,6 +22,8 @@
#include <errno.h>
#include "local.h"
+#define INITIAL_LEN 127 /* plus one for the NUL */
+
int
vasprintf(char **str, const char *fmt, __va_list ap)
{
@@ -33,10 +35,10 @@ vasprintf(char **str, const char *fmt, __va_list ap)
_FILEEXT_SETUP(&f, &fext);
f._file = -1;
f._flags = __SWR | __SSTR | __SALC;
- f._bf._base = f._p = malloc(128);
+ f._bf._base = f._p = malloc(INITIAL_LEN + 1);
if (f._bf._base == NULL)
goto err;
- f._bf._size = f._w = 127; /* Leave room for the NUL */
+ f._bf._size = f._w = INITIAL_LEN;
ret = __vfprintf(&f, fmt, ap);
if (ret == -1)
goto err;