summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <tb@cvs.openbsd.org>2016-02-09 01:29:13 +0000
committertb <tb@cvs.openbsd.org>2016-02-09 01:29:13 +0000
commit9d5ce990e427ceaabd8205b6b44768fa5e1450fa (patch)
treecc6e288afba621eb7f89a46028c174aca3e4b973
parentb96dcaf53c1230d8d33806a2d18a395d2963a8c6 (diff)
For a long time, nomem() has been a wrapper for err(1, NULL) and
meanwhile emalloc() has turned into calloc() by doing malloc + memset. Delete them and Use the libc functions directly instead. I've been running with this diff for ages and was reminded of it by a similar suggestion from mmcc@ and by recent diffs from Michal Mazurek. ok mmcc@
-rw-r--r--usr.bin/hexdump/display.c24
-rw-r--r--usr.bin/hexdump/hexdump.h5
-rw-r--r--usr.bin/hexdump/parse.c18
3 files changed, 16 insertions, 31 deletions
diff --git a/usr.bin/hexdump/display.c b/usr.bin/hexdump/display.c
index 2c755d61173..c153587d7b2 100644
--- a/usr.bin/hexdump/display.c
+++ b/usr.bin/hexdump/display.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: display.c,v 1.22 2016/02/08 22:09:22 schwarze Exp $ */
+/* $OpenBSD: display.c,v 1.23 2016/02/09 01:29:12 tb Exp $ */
/* $NetBSD: display.c,v 1.12 2001/12/07 15:14:29 bjh21 Exp $ */
/*
@@ -226,8 +226,9 @@ get(void)
u_char *tmpp;
if (!curp) {
- curp = emalloc(blocksize);
- savp = emalloc(blocksize);
+ if ((curp = calloc(1, blocksize)) == NULL ||
+ (savp = calloc(1, blocksize)) == NULL)
+ err(1, NULL);
} else {
tmpp = curp;
curp = savp;
@@ -348,20 +349,3 @@ doskip(const char *fname, int statok)
address += cnt;
skip -= cnt;
}
-
-void *
-emalloc(int allocsize)
-{
- void *p;
-
- if ((p = malloc((u_int)allocsize)) == NULL)
- nomem();
- memset(p, 0, allocsize);
- return(p);
-}
-
-void
-nomem(void)
-{
- err(1, NULL);
-}
diff --git a/usr.bin/hexdump/hexdump.h b/usr.bin/hexdump/hexdump.h
index 85244c32429..5f7711c8494 100644
--- a/usr.bin/hexdump/hexdump.h
+++ b/usr.bin/hexdump/hexdump.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: hexdump.h,v 1.10 2014/04/19 09:28:20 sobrado Exp $ */
+/* $OpenBSD: hexdump.h,v 1.11 2016/02/09 01:29:12 tb Exp $ */
/* $NetBSD: hexdump.h,v 1.7 2001/12/07 15:14:29 bjh21 Exp $ */
/*
@@ -93,13 +93,10 @@ void conv_c(PR *, u_char *);
void conv_u(PR *, u_char *);
void display(void);
void doskip(const char *, int);
-/*void err(const char *, ...);*/
-void *emalloc(int);
void escape(char *);
u_char *get(void);
void newsyntax(int, char ***);
int next(char **);
-void nomem(void);
void oldsyntax(int, char ***);
void rewrite(FS *);
int size(FS *);
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);