-/* $OpenBSD: config.h,v 1.26 2013/10/29 15:37:56 espie Exp $ */
+/* $OpenBSD: config.h,v 1.27 2014/05/18 09:29:54 espie Exp $ */
/* $NetBSD: config.h,v 1.30 1997/02/02 21:12:30 thorpej Exp $ */
/*
/* util.c */
void *emalloc(size_t);
-void *erealloc(void *, size_t);
+void *ereallocarray(void *, size_t, size_t);
+void *ecalloc(size_t, size_t);
char *sourcepath(const char *);
void error(const char *, ...); /* immediate errs */
void xerror(const char *, int, const char *, ...); /* delayed errs */
-/* $OpenBSD: hash.c,v 1.15 2011/10/02 22:20:49 edd Exp $ */
+/* $OpenBSD: hash.c,v 1.16 2014/05/18 09:29:54 espie Exp $ */
/* $NetBSD: hash.c,v 1.4 1996/11/07 22:59:43 gwr Exp $ */
/*
struct hashent **h;
u_int n;
- h = emalloc(sz * sizeof *h);
+ h = ereallocarray(NULL, sz, sizeof *h);
ht->ht_tab = h;
ht->ht_size = sz;
ht->ht_mask = sz - 1;
u_int n, i;
n = ht->ht_size * 2;
- h = emalloc(n * sizeof *h);
- for (i = 0; i < n; i++)
- h[i] = NULL;
+ h = ecalloc(n, sizeof *h);
oldh = ht->ht_tab;
n--;
for (i = ht->ht_size; i != 0; i--) {
-/* $OpenBSD: main.c,v 1.46 2013/11/23 17:38:15 deraadt Exp $ */
+/* $OpenBSD: main.c,v 1.47 2014/05/18 09:29:54 espie Exp $ */
/* $NetBSD: main.c,v 1.22 1997/02/02 21:12:33 thorpej Exp $ */
/*
for (nnewopts = 0, nv = options; nv != NULL; nv = nv->nv_next)
nnewopts++;
- newopts = (struct opt *)emalloc(nnewopts * sizeof(struct opt));
+ newopts = ereallocarray(NULL, nnewopts, sizeof(struct opt));
if (newopts == NULL)
ret = 0;
for (i = 0, nv = options; nv != NULL; nv = nv->nv_next, i++) {
-/* $OpenBSD: mkioconf.c,v 1.31 2011/10/02 22:20:50 edd Exp $ */
+/* $OpenBSD: mkioconf.c,v 1.32 2014/05/18 09:29:54 espie Exp $ */
/* $NetBSD: mkioconf.c,v 1.41 1996/11/11 14:18:49 mycroft Exp $ */
/*
if (locnames == NULL || nlocnames+1 > maxlocnames) {
maxlocnames *= 4;
- locnames = (char **)erealloc(locnames, maxlocnames * sizeof(char *));
+ locnames = ereallocarray(locnames, maxlocnames, sizeof(char *));
}
for (i = 0; i < nlocnames; i++)
if (strcmp(name, locnames[i]) == 0)
{
if (locnami == NULL || nlocnami+1 > maxlocnami) {
maxlocnami *= 4;
- locnami = (short *)erealloc(locnami, maxlocnami * sizeof(short));
+ locnami = ereallocarray(locnami, maxlocnami, sizeof(short));
}
locnami[nlocnami++] = index;
}
-/* $OpenBSD: pack.c,v 1.16 2011/10/02 22:20:50 edd Exp $ */
+/* $OpenBSD: pack.c,v 1.17 2014/05/18 09:29:54 espie Exp $ */
/* $NetBSD: pack.c,v 1.5 1996/08/31 21:15:11 mycroft Exp $ */
/*
}
/* Allocate and pack loc[]. */
- locators.vec = emalloc(locspace * sizeof(*locators.vec));
+ locators.vec = ereallocarray(NULL, locspace, sizeof(*locators.vec));
locators.used = 0;
packlocs();
/* Allocate and pack pv[]. */
- parents.vec = emalloc(pvecspace * sizeof(*parents.vec));
+ parents.vec = ereallocarray(NULL, pvecspace, sizeof(*parents.vec));
parents.used = 0;
packpvec();
}
struct deva *d;
int j, m, n;
- packed = emalloc((ndevi + 1) * sizeof *packed);
+ packed = ereallocarray(NULL, ndevi + 1, sizeof *packed);
n = 0;
for (d = alldevas; d != NULL; d = d->d_next) {
/*
return;
if (src->i_atdev != NULL) {
n = nparents(NULL, src->i_atdev, src->i_atunit);
- p = emalloc(n * sizeof *p);
+ p = ereallocarray(NULL, n, sizeof *p);
if (n == 0)
return;
(void)nparents(p, src->i_atdev, src->i_atunit);
n += nparents(NULL, nv->nv_ptr, src->i_atunit);
if (n == 0)
return;
- p = emalloc(n * sizeof *p);
+ p = ereallocarray(NULL, n, sizeof *p);
n = 0;
for (nv = src->i_atattr->a_refs; nv != NULL; nv = nv->nv_next)
n += nparents(p + n, nv->nv_ptr, src->i_atunit);
free(p);
return;
}
- dst->i_parents = q = erealloc(dst->i_parents, (new + 1) * sizeof(*q));
+ dst->i_parents = q = ereallocarray(dst->i_parents, new + 1, sizeof(*q));
dst->i_pvlen = new;
q[new] = NULL;
q += old;
int l, v, o;
short *vec;
- vec = emalloc(longest_pvec * sizeof(*vec));
+ vec = ereallocarray(NULL, longest_pvec, sizeof(*vec));
qsort(packed, npacked, sizeof *packed, pvlencmp);
for (p = packed; (i = *p) != NULL; p++) {
l = i->i_pvlen;
-/* $OpenBSD: sem.c,v 1.33 2013/11/23 17:38:15 deraadt Exp $ */
+/* $OpenBSD: sem.c,v 1.34 2014/05/18 09:29:54 espie Exp $ */
/* $NetBSD: sem.c,v 1.10 1996/11/11 23:40:11 gwr Exp $ */
/*
if (attr->a_loclen == 0) /* e.g., "at root" */
lp = nullvec;
else
- lp = emalloc((attr->a_loclen + 1) * sizeof(const char *));
+ lp = ereallocarray(NULL, attr->a_loclen + 1,
+ sizeof(const char *));
for (n = got; n != NULL; n = n->nv_next)
n->nv_int = -1;
nmissing = 0;
-/* $OpenBSD: util.c,v 1.13 2011/10/02 22:20:50 edd Exp $ */
+/* $OpenBSD: util.c,v 1.14 2014/05/18 09:29:54 espie Exp $ */
/* $NetBSD: util.c,v 1.5 1996/08/31 20:58:29 mycroft Exp $ */
/*
}
/*
- * Realloc, with abort on error.
+ * Reallocarray, with abort on error.
*/
void *
-erealloc(void *p, size_t size)
+ereallocarray(void *p, size_t sz1, size_t sz2)
{
- if ((p = realloc(p, size)) == NULL)
+ if ((p = reallocarray(p, sz1, sz2)) == NULL)
+ nomem();
+ return (p);
+}
+
+/*
+ * Calloc, with abort on error.
+ */
+void *
+ecalloc(size_t sz1, size_t sz2)
+{
+ void *p;
+
+ if ((p = calloc(sz1, sz2)) == NULL)
nomem();
return (p);
}