summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Unangst <tedu@cvs.openbsd.org>2015-09-25 16:16:27 +0000
committerTed Unangst <tedu@cvs.openbsd.org>2015-09-25 16:16:27 +0000
commitb21fa697e1d225c59c11cbb005316b8805ff289f (patch)
tree7078663751c1503acdac8b2a4e24e49b97dbe287
parent476217eb29093d7f01f8034efd43f0be3d7cd08b (diff)
xmalloc/free wrappers don't need to support 20 year old non comformance
-rw-r--r--usr.bin/diff/diffdir.c10
-rw-r--r--usr.bin/diff/diffreg.c18
-rw-r--r--usr.bin/diff/xmalloc.c26
3 files changed, 20 insertions, 34 deletions
diff --git a/usr.bin/diff/diffdir.c b/usr.bin/diff/diffdir.c
index dc6f17fd3c4..eac7497dccb 100644
--- a/usr.bin/diff/diffdir.c
+++ b/usr.bin/diff/diffdir.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: diffdir.c,v 1.43 2015/01/16 06:40:07 deraadt Exp $ */
+/* $OpenBSD: diffdir.c,v 1.44 2015/09/25 16:16:26 tedu Exp $ */
/*
* Copyright (c) 2003, 2010 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -166,13 +166,13 @@ diffdir(char *p1, char *p2, int flags)
closem:
if (dirp1 != NULL) {
for (dp1 = dirp1; dp1 < edp1; dp1++)
- xfree(*dp1);
- xfree(dirp1);
+ free(*dp1);
+ free(dirp1);
}
if (dirp2 != NULL) {
for (dp2 = dirp2; dp2 < edp2; dp2++)
- xfree(*dp2);
- xfree(dirp2);
+ free(*dp2);
+ free(dirp2);
}
}
diff --git a/usr.bin/diff/diffreg.c b/usr.bin/diff/diffreg.c
index 60eaec0209a..446fa359b22 100644
--- a/usr.bin/diff/diffreg.c
+++ b/usr.bin/diff/diffreg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: diffreg.c,v 1.86 2015/04/29 04:00:25 deraadt Exp $ */
+/* $OpenBSD: diffreg.c,v 1.87 2015/09/25 16:16:26 tedu Exp $ */
/*
* Copyright (C) Caldera International Inc. 2001-2002.
@@ -385,7 +385,7 @@ diffreg(char *file1, char *file2, int flags)
case -1:
warnx("No more processes");
status |= 2;
- xfree(header);
+ free(header);
rval = D_ERROR;
goto closem;
case 0:
@@ -406,7 +406,7 @@ diffreg(char *file1, char *file2, int flags)
}
close(pfd[0]);
rewind(stdout);
- xfree(header);
+ free(header);
}
}
prepare(0, f1, stb1.st_size, flags);
@@ -429,13 +429,13 @@ diffreg(char *file1, char *file2, int flags)
clistlen = 100;
clist = xcalloc(clistlen, sizeof(*clist));
i = stone(class, slen[0], member, klist, flags);
- xfree(member);
- xfree(class);
+ free(member);
+ free(class);
J = xreallocarray(J, len[0] + 2, sizeof(*J));
unravel(klist[i]);
- xfree(clist);
- xfree(klist);
+ free(clist);
+ free(klist);
ixold = xreallocarray(ixold, len[0] + 2, sizeof(*ixold));
ixnew = xreallocarray(ixnew, len[1] + 2, sizeof(*ixnew));
@@ -899,7 +899,7 @@ unsort(struct line *f, int l, int *b)
a[f[i].serial] = f[i].value;
for (i = 1; i <= l; i++)
b[i] = a[i];
- xfree(a);
+ free(a);
}
static int
@@ -1006,7 +1006,7 @@ ignoreline(char *line)
int ret;
ret = regexec(&ignore_re, line, 0, NULL, 0);
- xfree(line);
+ free(line);
return (ret == 0); /* if it matched, it should be ignored. */
}
diff --git a/usr.bin/diff/xmalloc.c b/usr.bin/diff/xmalloc.c
index 5d1483eaff7..610ab97de97 100644
--- a/usr.bin/diff/xmalloc.c
+++ b/usr.bin/diff/xmalloc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: xmalloc.c,v 1.7 2015/06/17 20:50:10 nicm Exp $ */
+/* $OpenBSD: xmalloc.c,v 1.8 2015/09/25 16:16:26 tedu Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -27,11 +27,9 @@ xmalloc(size_t size)
{
void *ptr;
- if (size == 0)
- errx(2, "xmalloc: zero size");
ptr = malloc(size);
if (ptr == NULL)
- err(2, NULL);
+ err(2, "xmalloc %zu", size);
return ptr;
}
@@ -40,14 +38,10 @@ xcalloc(size_t nmemb, size_t size)
{
void *ptr;
- if (size == 0 || nmemb == 0)
- errx(2, "xcalloc: zero size");
- if (SIZE_MAX / nmemb < size)
- errx(2, "xcalloc: nmemb * size > SIZE_MAX");
ptr = calloc(nmemb, size);
if (ptr == NULL)
- errx(2, "xcalloc: out of memory (allocating %lu bytes)",
- (u_long)(size * nmemb));
+ err(2, "xcalloc: out of memory (allocating %zu*%zu bytes)",
+ nmemb, size);
return ptr;
}
@@ -58,18 +52,10 @@ xreallocarray(void *ptr, size_t nmemb, size_t size)
new_ptr = reallocarray(ptr, nmemb, size);
if (new_ptr == NULL)
- err(2, NULL);
+ err(2, "xrealloc %zu*%zu", nmemb, size);
return new_ptr;
}
-void
-xfree(void *ptr)
-{
- if (ptr == NULL)
- err(2, NULL);
- free(ptr);
-}
-
char *
xstrdup(const char *str)
{
@@ -91,7 +77,7 @@ xasprintf(char **ret, const char *fmt, ...)
va_end(ap);
if (i < 0 || *ret == NULL)
- err(2, NULL);
+ err(2, "xasprintf");
return (i);
}