summaryrefslogtreecommitdiff
path: root/usr.bin/hexdump
diff options
context:
space:
mode:
authorTheo Buehler <tb@cvs.openbsd.org>2016-09-04 16:41:44 +0000
committerTheo Buehler <tb@cvs.openbsd.org>2016-09-04 16:41:44 +0000
commit2a19ee5b520e623e3816e087f6ed149c14edf264 (patch)
tree02f93630a181d4aacb5484d2518132815e4458c5 /usr.bin/hexdump
parentf611306a817f6be2961110f49d52ceb42215e2cc (diff)
Replace strlen + calloc + snprintf with asprintf.
ok martijn, beck, deraadt, gsoares
Diffstat (limited to 'usr.bin/hexdump')
-rw-r--r--usr.bin/hexdump/parse.c10
1 files changed, 3 insertions, 7 deletions
diff --git a/usr.bin/hexdump/parse.c b/usr.bin/hexdump/parse.c
index 321769903a4..103bf932d1c 100644
--- a/usr.bin/hexdump/parse.c
+++ b/usr.bin/hexdump/parse.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.c,v 1.21 2016/08/24 03:13:45 guenther Exp $ */
+/* $OpenBSD: parse.c,v 1.22 2016/09/04 16:41:43 tb Exp $ */
/* $NetBSD: parse.c,v 1.12 2001/12/07 13:37:39 bjh21 Exp $ */
/*
@@ -147,8 +147,7 @@ add(const char *fmt)
for (savep = ++p; *p != '"';)
if (*p++ == 0)
badfmt(fmt);
- tfu->fmt = strndup(savep, p - savep);
- if (tfu->fmt == NULL)
+ if ((tfu->fmt = strndup(savep, p - savep)) == NULL)
err(1, NULL);
escape(tfu->fmt);
p++;
@@ -219,7 +218,6 @@ rewrite(FS *fs)
char *p1, *p2;
char savech, *fmtp, cs[4];
int nconv, prec;
- size_t len;
nextpr = NULL;
prec = 0;
@@ -408,10 +406,8 @@ rewrite(FS *fs)
*/
savech = *p2;
p1[0] = '\0';
- len = strlen(fmtp) + strlen(cs) + 1;
- if ((pr->fmt = calloc(1, len)) == NULL)
+ if (asprintf(&pr->fmt, "%s%s", fmtp, cs) == -1)
err(1, NULL);
- snprintf(pr->fmt, len, "%s%s", fmtp, cs);
*p2 = savech;
pr->cchar = pr->fmt + (p1 - fmtp);
fmtp = p2;