Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/config Define ecalloc() and use it when initializin...



details:   https://anonhg.NetBSD.org/src/rev/6e63f88d72e9
branches:  trunk
changeset: 555668:6e63f88d72e9
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Nov 24 21:44:37 2003 +0000

description:
Define ecalloc() and use it when initializing data structures.

diffstat:

 usr.sbin/config/defs.h  |   3 ++-
 usr.sbin/config/files.c |   6 +++---
 usr.sbin/config/hash.c  |   6 +++---
 usr.sbin/config/pack.c  |   8 ++++----
 usr.sbin/config/scan.l  |   6 +++---
 usr.sbin/config/sem.c   |  17 ++++++++---------
 usr.sbin/config/util.c  |  19 ++++++++++++++++---
 7 files changed, 39 insertions(+), 26 deletions(-)

diffs (255 lines):

diff -r 9b2ea2d72336 -r 6e63f88d72e9 usr.sbin/config/defs.h
--- a/usr.sbin/config/defs.h    Mon Nov 24 20:54:59 2003 +0000
+++ b/usr.sbin/config/defs.h    Mon Nov 24 21:44:37 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: defs.h,v 1.15 2003/11/19 18:06:13 christos Exp $       */
+/*     $NetBSD: defs.h,v 1.16 2003/11/24 21:44:37 christos Exp $       */
 
 /*
  * Copyright (c) 1992, 1993
@@ -485,6 +485,7 @@
 void   initsem(void);
 
 /* util.c */
+void   *ecalloc(size_t, size_t);
 void   *emalloc(size_t);
 void   *erealloc(void *, size_t);
 char   *estrdup(const char *);
diff -r 9b2ea2d72336 -r 6e63f88d72e9 usr.sbin/config/files.c
--- a/usr.sbin/config/files.c   Mon Nov 24 20:54:59 2003 +0000
+++ b/usr.sbin/config/files.c   Mon Nov 24 21:44:37 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: files.c,v 1.22 2003/08/07 11:25:15 agc Exp $   */
+/*     $NetBSD: files.c,v 1.23 2003/11/24 21:44:37 christos Exp $      */
 
 /*
  * Copyright (c) 1992, 1993
@@ -117,7 +117,7 @@
         * Commit this file to memory.  We will decide later whether it
         * will be used after all.
         */
-       fi = emalloc(sizeof *fi);
+       fi = ecalloc(1, sizeof *fi);
        if (ht_insert(pathtab, path, fi)) {
                free(fi);
                if ((fi = ht_lookup(pathtab, path)) == NULL)
@@ -169,7 +169,7 @@
         * Commit this object to memory.  We will decide later whether it
         * will be used after all.
         */
-       oi = emalloc(sizeof *oi);
+       oi = ecalloc(1, sizeof *oi);
        if (ht_insert(pathtab, path, oi)) {
                free(oi);
                if ((oi = ht_lookup(pathtab, path)) == NULL)
diff -r 9b2ea2d72336 -r 6e63f88d72e9 usr.sbin/config/hash.c
--- a/usr.sbin/config/hash.c    Mon Nov 24 20:54:59 2003 +0000
+++ b/usr.sbin/config/hash.c    Mon Nov 24 21:44:37 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: hash.c,v 1.11 2003/08/07 11:25:15 agc Exp $    */
+/*     $NetBSD: hash.c,v 1.12 2003/11/24 21:44:37 christos Exp $       */
 
 /*
  * Copyright (c) 1992, 1993
@@ -138,7 +138,7 @@
        struct hashent *hp;
 
        if (TAILQ_EMPTY(&hefreelist))
-               hp = emalloc(sizeof(*hp));
+               hp = ecalloc(1, sizeof(*hp));
        else {
                hp = TAILQ_FIRST(&hefreelist);
                TAILQ_REMOVE(&hefreelist, hp, h_next);
@@ -202,7 +202,7 @@
 {
        struct hashtab *ht;
 
-       ht = emalloc(sizeof *ht);
+       ht = ecalloc(1, sizeof *ht);
        ht_init(ht, 8);
        return (ht);
 }
diff -r 9b2ea2d72336 -r 6e63f88d72e9 usr.sbin/config/pack.c
--- a/usr.sbin/config/pack.c    Mon Nov 24 20:54:59 2003 +0000
+++ b/usr.sbin/config/pack.c    Mon Nov 24 21:44:37 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pack.c,v 1.14 2003/08/07 11:25:17 agc Exp $    */
+/*     $NetBSD: pack.c,v 1.15 2003/11/24 21:44:37 christos Exp $       */
 
 /*
  * Copyright (c) 1992, 1993
@@ -119,7 +119,7 @@
        }
 
        /* Allocate and pack loc[]. */
-       locators.vec = emalloc(locspace * sizeof(*locators.vec));
+       locators.vec = ecalloc(locspace, sizeof(*locators.vec));
        locators.used = 0;
        packlocs();
 }
@@ -167,7 +167,7 @@
                }
        }
 
-       packed = emalloc((ndevi + 1) * sizeof *packed);
+       packed = ecalloc(ndevi + 1, sizeof *packed);
        n = 0;
        TAILQ_FOREACH(d, &allbases, d_next) {
                /*
@@ -263,7 +263,7 @@
                if (off >= 0 && (*cmp)(ptr, off, len))
                        return (off);
        }
-       t = emalloc(sizeof(*t));
+       t = ecalloc(1, sizeof(*t));
        t->t_next = *hp;
        *hp = t;
        t->t_ends_at = nextplace + len;
diff -r 9b2ea2d72336 -r 6e63f88d72e9 usr.sbin/config/scan.l
--- a/usr.sbin/config/scan.l    Mon Nov 24 20:54:59 2003 +0000
+++ b/usr.sbin/config/scan.l    Mon Nov 24 21:44:37 2003 +0000
@@ -1,5 +1,5 @@
 %{
-/*     $NetBSD: scan.l,v 1.42 2003/11/19 18:06:13 christos Exp $       */
+/*     $NetBSD: scan.l,v 1.43 2003/11/24 21:44:37 christos Exp $       */
 
 /*
  * Copyright (c) 1992, 1993
@@ -215,7 +215,7 @@
                sprintf(p, "%s/%s", cwd, d);
        }
        free(f);
-       pf = emalloc(sizeof(*pf));
+       pf = ecalloc(1, sizeof(*pf));
        pf->pf_prefix = p;
        SLIST_INSERT_HEAD(&curdirs, pf, pf_next);
 
@@ -332,7 +332,7 @@
                free(s);
                return (-1);
        }
-       in = emalloc(sizeof *in);
+       in = ecalloc(1, sizeof *in);
        in->in_prev = incl;
        in->in_buf = YY_CURRENT_BUFFER;
        in->in_fname = yyfile;
diff -r 9b2ea2d72336 -r 6e63f88d72e9 usr.sbin/config/sem.c
--- a/usr.sbin/config/sem.c     Mon Nov 24 20:54:59 2003 +0000
+++ b/usr.sbin/config/sem.c     Mon Nov 24 21:44:37 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sem.c,v 1.40 2003/08/07 11:25:17 agc Exp $     */
+/*     $NetBSD: sem.c,v 1.41 2003/11/24 21:44:37 christos Exp $        */
 
 /*
  * Copyright (c) 1992, 1993
@@ -210,7 +210,7 @@
                }
        }
 
-       a = emalloc(sizeof *a);
+       a = ecalloc(1, sizeof *a);
        if (ht_insert(attrtab, name, a)) {
                free(a);
                error("attribute `%s' already defined", name);
@@ -401,7 +401,7 @@
        }
        dev = ht_lookup(devbasetab, name);
        if (dev == NULL) {
-               dev = emalloc(sizeof *dev);
+               dev = ecalloc(1, sizeof *dev);
                dev->d_name = name;
                dev->d_isdef = 0;
                dev->d_major = NODEV;
@@ -531,7 +531,7 @@
        }
        deva = ht_lookup(devatab, name);
        if (deva == NULL) {
-               deva = emalloc(sizeof *deva);
+               deva = ecalloc(1, sizeof *deva);
                deva->d_name = name;
                deva->d_bsame = NULL;
                deva->d_isdef = 0;
@@ -767,7 +767,7 @@
        const char *name;
 
        name = cf0->cf_name;
-       cf = emalloc(sizeof *cf);
+       cf = ecalloc(1, sizeof *cf);
        if (ht_insert(cfhashtab, name, cf)) {
                error("configuration `%s' already defined", name);
                free(cf);
@@ -850,7 +850,7 @@
 {
        struct devi *i;
 
-       i = emalloc(sizeof *i);
+       i = ecalloc(1, sizeof *i);
        i->i_name = name;
        i->i_unit = unit;
        i->i_base = d;
@@ -1129,7 +1129,7 @@
                return;
        }
 
-       dm = emalloc(sizeof(*dm));
+       dm = ecalloc(1, sizeof(*dm));
        dm->dm_srcfile = yyfile;
        dm->dm_srcline = currentline();
        dm->dm_name = name;
@@ -1170,8 +1170,7 @@
                        return (p);
        }
 
-       p = emalloc(sizeof(*p));
-       memset(p, 0, sizeof(*p));
+       p = ecalloc(1, sizeof(*p));
 
        p->p_iattr = attr;
        p->p_atdev = ab;
diff -r 9b2ea2d72336 -r 6e63f88d72e9 usr.sbin/config/util.c
--- a/usr.sbin/config/util.c    Mon Nov 24 20:54:59 2003 +0000
+++ b/usr.sbin/config/util.c    Mon Nov 24 21:44:37 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: util.c,v 1.18 2003/09/19 06:19:56 itojun Exp $ */
+/*     $NetBSD: util.c,v 1.19 2003/11/24 21:44:37 christos Exp $       */
 
 /*
  * Copyright (c) 1992, 1993
@@ -58,6 +58,19 @@
      __attribute__((__format__(__printf__, 4, 0)));
 
 /*
+ * Calloc, with abort on error.
+ */
+void *
+ecalloc(size_t nelem, size_t size)
+{
+       void *p;
+
+       if ((p = calloc(nelem, size)) == NULL)
+               nomem();
+       return (p);
+}
+
+/*
  * Malloc, with abort on error.
  */
 void *
@@ -114,7 +127,7 @@
        struct prefix *pf;
        char *cp;
 
-       pf = emalloc(sizeof(struct prefix));
+       pf = ecalloc(1, sizeof(struct prefix));
 
        if (! SLIST_EMPTY(&prefixes) && *path != '/') {
                cp = emalloc(strlen(SLIST_FIRST(&prefixes)->pf_prefix) + 1 +
@@ -187,7 +200,7 @@
        struct nvlist *nv;
 
        if ((nv = nvfreelist) == NULL)
-               nv = emalloc(sizeof(*nv));
+               nv = ecalloc(1, sizeof(*nv));
        else
                nvfreelist = nv->nv_next;
        nv->nv_next = next;



Home | Main Index | Thread Index | Old Index