summaryrefslogtreecommitdiffstats
path: root/usr.bin/diff/xmalloc.c
diff options
context:
space:
mode:
authortobias <tobias@openbsd.org>2015-11-17 18:25:02 +0000
committertobias <tobias@openbsd.org>2015-11-17 18:25:02 +0000
commit6d42169eec9bde30db4a01274d6ae9f9a3349815 (patch)
tree8cf7011409fc7147df2bd695c219304fdb97bedd /usr.bin/diff/xmalloc.c
parentsync to mv (diff)
downloadwireguard-openbsd-6d42169eec9bde30db4a01274d6ae9f9a3349815.tar.xz
wireguard-openbsd-6d42169eec9bde30db4a01274d6ae9f9a3349815.zip
Merge xmalloc.[ch] files across base, skipping OpenSSH for now.
ok nicm
Diffstat (limited to 'usr.bin/diff/xmalloc.c')
-rw-r--r--usr.bin/diff/xmalloc.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/usr.bin/diff/xmalloc.c b/usr.bin/diff/xmalloc.c
index 610ab97de97..a17c3fe5783 100644
--- a/usr.bin/diff/xmalloc.c
+++ b/usr.bin/diff/xmalloc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: xmalloc.c,v 1.8 2015/09/25 16:16:26 tedu Exp $ */
+/* $OpenBSD: xmalloc.c,v 1.9 2015/11/17 18:25:02 tobias Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -27,9 +27,11 @@ xmalloc(size_t size)
{
void *ptr;
+ if (size == 0)
+ errx(2, "xmalloc: zero size");
ptr = malloc(size);
if (ptr == NULL)
- err(2, "xmalloc %zu", size);
+ err(2, "xmalloc: allocating %zu bytes", size);
return ptr;
}
@@ -40,8 +42,7 @@ xcalloc(size_t nmemb, size_t size)
ptr = calloc(nmemb, size);
if (ptr == NULL)
- err(2, "xcalloc: out of memory (allocating %zu*%zu bytes)",
- nmemb, size);
+ err(2, "xcalloc: allocating %zu * %zu bytes", nmemb, size);
return ptr;
}
@@ -52,7 +53,8 @@ xreallocarray(void *ptr, size_t nmemb, size_t size)
new_ptr = reallocarray(ptr, nmemb, size);
if (new_ptr == NULL)
- err(2, "xrealloc %zu*%zu", nmemb, size);
+ err(2, "xreallocarray: allocating %zu * %zu bytes",
+ nmemb, size);
return new_ptr;
}
@@ -62,7 +64,7 @@ xstrdup(const char *str)
char *cp;
if ((cp = strdup(str)) == NULL)
- err(1, "xstrdup");
+ err(2, "xstrdup");
return cp;
}
@@ -79,5 +81,5 @@ xasprintf(char **ret, const char *fmt, ...)
if (i < 0 || *ret == NULL)
err(2, "xasprintf");
- return (i);
+ return i;
}