summaryrefslogtreecommitdiff
path: root/xmalloc.c
diff options
context:
space:
mode:
authorBen Lindstrom <mouring@eviladmin.org>2001-02-10 23:34:54 +0000
committerBen Lindstrom <mouring@eviladmin.org>2001-02-10 23:34:54 +0000
commita905ecd994ad19a733538bb2093d919e85923b98 (patch)
tree8c935684640f19fa529eb258b293253c2faa1a67 /xmalloc.c
parent70ea46a382befd3100020b135d5ff440c51c3bd5 (diff)
- deraadt 2001/02/07 8:57:26
[xmalloc.c] deal with new ANSI malloc stuff - markus@cvs.openbsd.org 2001/02/07 16:46:08 [xmalloc.c] typo in fatal() - itojun@cvs.openbsd.org 2001/02/07 18:04:50 [xmalloc.c] fix size_t -> int cast (use u_long). markus ok
Diffstat (limited to 'xmalloc.c')
-rw-r--r--xmalloc.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/xmalloc.c b/xmalloc.c
index 1a471889..8a23b8b7 100644
--- a/xmalloc.c
+++ b/xmalloc.c
@@ -13,7 +13,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: xmalloc.c,v 1.11 2001/02/04 15:32:27 stevesk Exp $");
+RCSID("$OpenBSD: xmalloc.c,v 1.14 2001/02/07 18:04:50 itojun Exp $");
#include "xmalloc.h"
#include "log.h"
@@ -21,9 +21,13 @@ RCSID("$OpenBSD: xmalloc.c,v 1.11 2001/02/04 15:32:27 stevesk Exp $");
void *
xmalloc(size_t size)
{
- void *ptr = malloc(size);
+ void *ptr;
+
+ if (size == 0)
+ fatal("xmalloc: zero size");
+ ptr = malloc(size);
if (ptr == NULL)
- fatal("xmalloc: out of memory (allocating %d bytes)", (int) size);
+ fatal("xmalloc: out of memory (allocating %lu bytes)", (u_long) size);
return ptr;
}
@@ -32,11 +36,13 @@ xrealloc(void *ptr, size_t new_size)
{
void *new_ptr;
+ if (new_size == 0)
+ fatal("xrealloc: zero size");
if (ptr == NULL)
fatal("xrealloc: NULL pointer given as argument");
new_ptr = realloc(ptr, new_size);
if (new_ptr == NULL)
- fatal("xrealloc: out of memory (new_size %d bytes)", (int) new_size);
+ fatal("xrealloc: out of memory (new_size %lu bytes)", (u_long) new_size);
return new_ptr;
}
@@ -52,8 +58,11 @@ char *
xstrdup(const char *str)
{
size_t len = strlen(str) + 1;
+ char *cp;
- char *cp = xmalloc(len);
+ if (len == 0)
+ fatal("xstrdup: zero size");
+ cp = xmalloc(len);
strlcpy(cp, str, len);
return cp;
}