-/* $OpenBSD: dump.c,v 1.5 2013/05/22 12:14:08 espie Exp $ */
+/* $OpenBSD: dump.c,v 1.6 2014/05/18 08:08:50 espie Exp $ */
/*
* Copyright (c) 2012 Marc Espie.
*
unsigned int i, j;
void *e;
size_t n = ohash_entries(h);
- void **t = emalloc(sizeof(void *) * (n+1));
+ void **t = ereallocarray(NULL, n+1, sizeof(void *));
cmp_offset = h->info.key_offset;
for (i = 0, e = ohash_first(h, &j); e != NULL; e = ohash_next(h, &j))
#ifndef GARRAY_H
#define GARRAY_H
-/* $OpenBSD: garray.h,v 1.8 2014/05/12 19:11:19 espie Exp $ */
+/* $OpenBSD: garray.h,v 1.9 2014/05/18 08:08:50 espie Exp $ */
/* Growable array implementation */
/*
do { \
(l)->size = (sz); \
(l)->n = 0; \
- (l)->a = emalloc(sizeof(GNode *) * (l)->size); \
+ (l)->a = ereallocarray(NULL, (l)->size, sizeof(GNode *)); \
} while (0)
#define Array_Reset(l) \
-/* $OpenBSD: generate.c,v 1.15 2013/04/23 14:32:53 espie Exp $ */
+/* $OpenBSD: generate.c,v 1.16 2014/05/18 08:08:50 espie Exp $ */
/*
* Copyright (c) 2001 Marc Espie.
t = table[tn-1];
slots = atoi(argv[2]);
if (slots) {
- occupied = calloc(sizeof(char *), slots);
+ occupied = calloc(slots, sizeof(char *));
if (!occupied)
exit(1);
- for (i = 0; i < slots; i++)
- occupied[i] = NULL;
} else
occupied = NULL;
-/* $OpenBSD: memory.c,v 1.10 2014/05/12 19:11:19 espie Exp $ */
+/* $OpenBSD: memory.c,v 1.11 2014/05/18 08:08:50 espie Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
return ptr;
}
-void *
-ecalloc(size_t s1, size_t s2)
-{
- void *p;
-
- if ((p = calloc(s1, s2)) == NULL)
- enocmem(s1, s2);
- return p;
-}
-
void *
ereallocarray(void *ptr, size_t s1, size_t s2)
{
void *
hash_calloc(size_t n, size_t s, void *u UNUSED)
{
- return ecalloc(n, s);
+ void *p;
+
+ if ((p = calloc(n, s)) == NULL)
+ enocmem(n, s);
+ return p;
}
void
#ifndef MEMORY_H
#define MEMORY_H
-/* $OpenBSD: memory.h,v 1.8 2014/05/12 19:11:19 espie Exp $ */
+/* $OpenBSD: memory.h,v 1.9 2014/05/18 08:08:50 espie Exp $ */
/*-
* Copyright (c) 1988, 1989, 1990, 1993
extern void *emalloc(size_t);
extern char *estrdup(const char *);
extern void *erealloc(void *, size_t);
-extern void *ecalloc(size_t, size_t);
extern void *ereallocarray(void *, size_t, size_t);
extern int eunlink(const char *);
extern void esetenv(const char *, const char *);
-/* $OpenBSD: str.c,v 1.30 2014/05/12 19:11:19 espie Exp $ */
+/* $OpenBSD: str.c,v 1.31 2014/05/18 08:08:50 espie Exp $ */
/* $NetBSD: str.c,v 1.13 1996/11/06 17:59:23 christos Exp $ */
/*-
size_t len;
int argmax = 50;
size_t curlen = 0;
- char **argv = emalloc((argmax + 1) * sizeof(char *));
+ char **argv = ereallocarray(NULL, argmax + 1, sizeof(char *));
/* skip leading space chars. */
for (; *str == ' ' || *str == '\t'; ++str)
-/* $OpenBSD: varmodifiers.c,v 1.37 2014/05/12 19:11:19 espie Exp $ */
+/* $OpenBSD: varmodifiers.c,v 1.38 2014/05/18 08:08:50 espie Exp $ */
/* $NetBSD: var.c,v 1.18 1997/03/18 19:24:46 christos Exp $ */
/*
p2.nsub = 1;
if (p2.nsub > 10)
p2.nsub = 10;
- p2.matches = emalloc(p2.nsub * sizeof(regmatch_t));
+ p2.matches = ereallocarray(NULL, p2.nsub, sizeof(regmatch_t));
result = VarModify((char *)s, VarRESubstitute, &p2);
regfree(&p2.re);
free(p2.matches);