summaryrefslogtreecommitdiff
path: root/usr.bin/make
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2014-05-18 08:08:51 +0000
committerMarc Espie <espie@cvs.openbsd.org>2014-05-18 08:08:51 +0000
commitbf73e6ad642681c23ce61a4a312483138e3811e2 (patch)
treea42ea45736969e82e4384dfb8fd3a084a37a7f54 /usr.bin/make
parentf5e4591067b60e90f1583fec44aa9694a319b7ce (diff)
a bit more reallocarray (and kill ecalloc, which isn't used)
okay chl@
Diffstat (limited to 'usr.bin/make')
-rw-r--r--usr.bin/make/dump.c4
-rw-r--r--usr.bin/make/garray.h4
-rw-r--r--usr.bin/make/generate.c6
-rw-r--r--usr.bin/make/memory.c18
-rw-r--r--usr.bin/make/memory.h3
-rw-r--r--usr.bin/make/str.c4
-rw-r--r--usr.bin/make/varmodifiers.c4
7 files changed, 17 insertions, 26 deletions
diff --git a/usr.bin/make/dump.c b/usr.bin/make/dump.c
index 1212bff8900..3b688f74c9e 100644
--- a/usr.bin/make/dump.c
+++ b/usr.bin/make/dump.c
@@ -1,4 +1,4 @@
-/* $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.
*
@@ -67,7 +67,7 @@ sort_ohash(struct ohash *h, int (*comparison)(const void *, const void *))
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))
diff --git a/usr.bin/make/garray.h b/usr.bin/make/garray.h
index 4cd33699bfd..13bb4840243 100644
--- a/usr.bin/make/garray.h
+++ b/usr.bin/make/garray.h
@@ -1,7 +1,7 @@
#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 */
/*
@@ -108,7 +108,7 @@ do { \
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) \
diff --git a/usr.bin/make/generate.c b/usr.bin/make/generate.c
index c771be705a0..9e63e600877 100644
--- a/usr.bin/make/generate.c
+++ b/usr.bin/make/generate.c
@@ -1,4 +1,4 @@
-/* $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.
@@ -152,11 +152,9 @@ main(int argc, char *argv[])
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;
diff --git a/usr.bin/make/memory.c b/usr.bin/make/memory.c
index 1b2ec463ef1..6b3a53197b0 100644
--- a/usr.bin/make/memory.c
+++ b/usr.bin/make/memory.c
@@ -1,4 +1,4 @@
-/* $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
@@ -94,16 +94,6 @@ erealloc(void *ptr, size_t size)
}
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)
{
if ((ptr = reallocarray(ptr, s1, s2)) == NULL)
@@ -115,7 +105,11 @@ 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
diff --git a/usr.bin/make/memory.h b/usr.bin/make/memory.h
index 70e7bfd111b..953db7f8c02 100644
--- a/usr.bin/make/memory.h
+++ b/usr.bin/make/memory.h
@@ -1,7 +1,7 @@
#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
@@ -41,7 +41,6 @@
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 *);
diff --git a/usr.bin/make/str.c b/usr.bin/make/str.c
index b4dfc7ac5a4..32d6305d91c 100644
--- a/usr.bin/make/str.c
+++ b/usr.bin/make/str.c
@@ -1,4 +1,4 @@
-/* $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 $ */
/*-
@@ -97,7 +97,7 @@ brk_string(const char *str, int *store_argc, char **buffer)
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)
diff --git a/usr.bin/make/varmodifiers.c b/usr.bin/make/varmodifiers.c
index e12dde88714..4765cc7eb41 100644
--- a/usr.bin/make/varmodifiers.c
+++ b/usr.bin/make/varmodifiers.c
@@ -1,4 +1,4 @@
-/* $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 $ */
/*
@@ -1414,7 +1414,7 @@ do_regex(const char *s, const struct Name *n UNUSED, void *arg)
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);