summaryrefslogtreecommitdiff
path: root/usr.bin/hexdump/parse.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/hexdump/parse.c')
-rw-r--r--usr.bin/hexdump/parse.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/usr.bin/hexdump/parse.c b/usr.bin/hexdump/parse.c
index 9256a42ac62..98e1f301a47 100644
--- a/usr.bin/hexdump/parse.c
+++ b/usr.bin/hexdump/parse.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.c,v 1.17 2009/10/27 23:59:39 deraadt Exp $ */
+/* $OpenBSD: parse.c,v 1.18 2016/02/09 01:29:12 tb Exp $ */
/* $NetBSD: parse.c,v 1.12 2001/12/07 13:37:39 bjh21 Exp $ */
/*
@@ -86,7 +86,8 @@ add(const char *fmt)
const char *savep;
/* start new linked list of format units */
- tfs = emalloc(sizeof(FS));
+ if ((tfs = calloc(1, sizeof(FS))) == NULL)
+ err(1, NULL);
if (!fshead)
fshead = tfs;
else
@@ -102,7 +103,8 @@ add(const char *fmt)
break;
/* allocate a new format unit and link it in */
- tfu = emalloc(sizeof(FU));
+ if ((tfu = calloc(1, sizeof(FU))) == NULL)
+ err(1, NULL);
*nextfu = tfu;
nextfu = &tfu->nextfu;
tfu->reps = 1;
@@ -139,8 +141,8 @@ add(const char *fmt)
for (savep = ++p; *p != '"';)
if (*p++ == 0)
badfmt(fmt);
- if (!(tfu->fmt = malloc(p - savep + 1)))
- nomem();
+ if ((tfu->fmt = malloc(p - savep + 1)) == NULL)
+ err(1, NULL);
(void) strncpy(tfu->fmt, savep, p - savep);
tfu->fmt[p - savep] = '\0';
escape(tfu->fmt);
@@ -222,7 +224,8 @@ rewrite(FS *fs)
* character gets its own.
*/
for (nconv = 0, fmtp = fu->fmt; *fmtp; nextpr = &pr->nextpr) {
- pr = emalloc(sizeof(PR));
+ if ((pr = calloc(1, sizeof(PR))) == NULL)
+ err(1, NULL);
if (!fu->nextpr)
fu->nextpr = pr;
else
@@ -399,7 +402,8 @@ rewrite(FS *fs)
savech = *p2;
p1[0] = '\0';
len = strlen(fmtp) + strlen(cs) + 1;
- pr->fmt = emalloc(len);
+ if ((pr->fmt = calloc(1, len)) == NULL)
+ err(1, NULL);
snprintf(pr->fmt, len, "%s%s", fmtp, cs);
*p2 = savech;
pr->cchar = pr->fmt + (p1 - fmtp);