summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2005-05-28 00:54:51 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2005-05-28 00:54:51 +0000
commit5869e8098c014ddcd7b3f0663e8187bed29ecafe (patch)
tree01bc02b8bdee38e002737a5ceb33b3415dc7b19f /lib
parent303c13de1017e23f84c1d2cb60f3166c76d314d1 (diff)
Move the va_start()/va_end() pair such that it directly backets the call
to vfprintf() like the rest of the *printf functions. This is clearer and makes the error case in asprintf() simpler. From Andrey Matveev.
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/stdio/asprintf.c9
-rw-r--r--lib/libc/stdio/snprintf.c6
2 files changed, 7 insertions, 8 deletions
diff --git a/lib/libc/stdio/asprintf.c b/lib/libc/stdio/asprintf.c
index 72c217a4119..784a19ff514 100644
--- a/lib/libc/stdio/asprintf.c
+++ b/lib/libc/stdio/asprintf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: asprintf.c,v 1.12 2005/04/30 09:25:17 espie Exp $ */
+/* $OpenBSD: asprintf.c,v 1.13 2005/05/28 00:54:50 millert Exp $ */
/*
* Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -17,7 +17,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: asprintf.c,v 1.12 2005/04/30 09:25:17 espie Exp $";
+static char rcsid[] = "$OpenBSD: asprintf.c,v 1.13 2005/05/28 00:54:50 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
@@ -36,14 +36,15 @@ asprintf(char **str, const char *fmt, ...)
unsigned char *_base;
_FILEEXT_SETUP(&f, &fext);
- va_start(ap, fmt);
f._file = -1;
f._flags = __SWR | __SSTR | __SALC;
f._bf._base = f._p = (unsigned char *)malloc(128);
if (f._bf._base == NULL)
goto err;
f._bf._size = f._w = 127; /* Leave room for the NUL */
+ va_start(ap, fmt);
ret = vfprintf(&f, fmt, ap);
+ va_end(ap);
if (ret == -1)
goto err;
*f._p = '\0';
@@ -51,11 +52,9 @@ asprintf(char **str, const char *fmt, ...)
if (_base == NULL)
goto err;
*str = (char *)_base;
- va_end(ap);
return (ret);
err:
- va_end(ap);
if (f._bf._base) {
free(f._bf._base);
f._bf._base = NULL;
diff --git a/lib/libc/stdio/snprintf.c b/lib/libc/stdio/snprintf.c
index 653d0f01f08..7291c08aa66 100644
--- a/lib/libc/stdio/snprintf.c
+++ b/lib/libc/stdio/snprintf.c
@@ -31,7 +31,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: snprintf.c,v 1.11 2005/04/30 09:25:17 espie Exp $";
+static char rcsid[] = "$OpenBSD: snprintf.c,v 1.12 2005/05/28 00:54:50 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#include <limits.h>
@@ -56,14 +56,14 @@ snprintf(char *str, size_t n, const char *fmt, ...)
str = &dummy;
n = 1;
}
- va_start(ap, fmt);
_FILEEXT_SETUP(&f, &fext);
f._file = -1;
f._flags = __SWR | __SSTR;
f._bf._base = f._p = (unsigned char *)str;
f._bf._size = f._w = n - 1;
+ va_start(ap, fmt);
ret = vfprintf(&f, fmt, ap);
- *f._p = '\0';
va_end(ap);
+ *f._p = '\0';
return (ret);
}