summaryrefslogtreecommitdiff
path: root/lib/libc
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2017-03-14 16:46:06 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2017-03-14 16:46:06 +0000
commite7db088dadd801c12b28172cac28541f03fdc557 (patch)
treed73ea25f60ae3f9f2bcf740452f45e26c2ef8f05 /lib/libc
parent5fff60ac1f80ee6d02edf70ed3c2e584ad26a3c0 (diff)
Use a macro for the initial length of the buffer instead of 127; OK deraadt@
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/stdio/asprintf.c8
-rw-r--r--lib/libc/stdio/vasprintf.c8
2 files changed, 10 insertions, 6 deletions
diff --git a/lib/libc/stdio/asprintf.c b/lib/libc/stdio/asprintf.c
index 48236775908..175765b196d 100644
--- a/lib/libc/stdio/asprintf.c
+++ b/lib/libc/stdio/asprintf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: asprintf.c,v 1.22 2015/12/28 22:08:18 mmcc Exp $ */
+/* $OpenBSD: asprintf.c,v 1.23 2017/03/14 16:46:05 millert Exp $ */
/*
* Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -23,6 +23,8 @@
#include <stdarg.h>
#include "local.h"
+#define INITIAL_LEN 127 /* plus one for the NUL */
+
int
asprintf(char **str, const char *fmt, ...)
{
@@ -35,10 +37,10 @@ asprintf(char **str, const char *fmt, ...)
_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;
va_start(ap, fmt);
ret = __vfprintf(&f, fmt, ap);
va_end(ap);
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;