summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2005-11-14 15:30:55 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2005-11-14 15:30:55 +0000
commit2df30963d1c216def27935548d301b2b7157823d (patch)
tree52e5a6f0ba05b488d0ddb024938644f126b80e9a
parent425690afdf206dd1a4c2cbc47f0b0f014228afeb (diff)
use asprintf()
-rw-r--r--usr.bin/apply/apply.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/usr.bin/apply/apply.c b/usr.bin/apply/apply.c
index 43e15c710bd..e5d1893f68e 100644
--- a/usr.bin/apply/apply.c
+++ b/usr.bin/apply/apply.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: apply.c,v 1.21 2005/05/15 16:22:12 jaredy Exp $ */
+/* $OpenBSD: apply.c,v 1.22 2005/11/14 15:30:54 deraadt Exp $ */
/* $NetBSD: apply.c,v 1.3 1995/03/25 03:38:23 glass Exp $ */
/*-
@@ -37,7 +37,7 @@
#if 0
static const char sccsid[] = "@(#)apply.c 8.4 (Berkeley) 4/4/94";
#else
-static const char rcsid[] = "$OpenBSD: apply.c,v 1.21 2005/05/15 16:22:12 jaredy Exp $";
+static const char rcsid[] = "$OpenBSD: apply.c,v 1.22 2005/11/14 15:30:54 deraadt Exp $";
#endif
#endif /* not lint */
@@ -110,14 +110,14 @@ main(int argc, char *argv[])
* the end to consume (nargs) arguments each time round the loop.
* Allocate enough space to hold the maximum command.
*/
- len = sizeof("exec ") - 1 +
- strlen(argv[0]) + 9 * (sizeof(" %1") - 1) + 1;
- if ((cmd = malloc(len)) == NULL)
- err(1, NULL);
-
if (n == 0) {
int l;
+ len = sizeof("exec ") - 1 +
+ strlen(argv[0]) + 9 * (sizeof(" %1") - 1) + 1;
+ if ((cmd = malloc(len)) == NULL)
+ err(1, NULL);
+
/* If nargs not set, default to a single argument. */
if (nargs == -1)
nargs = 1;
@@ -143,7 +143,8 @@ main(int argc, char *argv[])
if (nargs == 0)
nargs = 1;
} else {
- (void)snprintf(cmd, len, "exec %s", argv[0]);
+ if (asprintf(&cmd, "exec %s", argv[0]) == -1)
+ err(1, NULL);
nargs = n;
}