Remove the misnamed `emalloc' and replace its uses with the calloc (along

with error checking) that it actually was.
This commit is contained in:
David E. O'Brien 2001-07-24 14:11:09 +00:00
parent de9b3b9034
commit ac3c230c82
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=80290
3 changed files with 14 additions and 26 deletions

View File

@ -238,8 +238,10 @@ get()
u_char *tmpp;
if (!curp) {
curp = emalloc(blocksize);
savp = emalloc(blocksize);
if ((curp = calloc(1, blocksize)) == NULL)
err(1, NULL);
if ((savp = calloc(1, blocksize)) == NULL)
err(1, NULL);
} else {
tmpp = curp;
curp = savp;
@ -366,21 +368,3 @@ doskip(fname, statok)
skip -= cnt;
}
}
void *
emalloc(size)
int size;
{
void *p;
if ((p = malloc((u_int)size)) == NULL)
nomem();
bzero(p, size);
return(p);
}
void
nomem()
{
err(1, NULL);
}

View File

@ -31,6 +31,7 @@
* SUCH DAMAGE.
*
* @(#)hexdump.h 8.1 (Berkeley) 6/6/93
* $FreeBSD$
*/
typedef struct _pr {
@ -85,7 +86,6 @@ void conv_c __P((PR *, u_char *));
void conv_u __P((PR *, u_char *));
void display __P((void));
void doskip __P((char *, int));
void *emalloc __P((int));
void escape __P((char *));
u_char *get __P((void));
void newsyntax __P((int, char ***));

View File

@ -87,7 +87,8 @@ add(fmt)
FU *tfu, **nextfu;
/* 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
@ -103,7 +104,8 @@ add(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;
@ -141,7 +143,7 @@ add(fmt)
if (*p++ == 0)
badfmt(fmt);
if (!(tfu->fmt = malloc(p - savep + 1)))
nomem();
err(1, NULL);
(void) strncpy(tfu->fmt, savep, p - savep);
tfu->fmt[p - savep] = '\0';
escape(tfu->fmt);
@ -222,7 +224,8 @@ rewrite(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
@ -385,7 +388,8 @@ isint2: switch(fu->bcnt) {
*/
savech = *p2;
p1[0] = '\0';
pr->fmt = emalloc(strlen(fmtp) + 2);
if ((pr->fmt = calloc(1, strlen(fmtp) + 2)) == NULL)
err(1, NULL);
(void)strcpy(pr->fmt, fmtp);
(void)strcat(pr->fmt, cs);
*p2 = savech;