summaryrefslogtreecommitdiff
path: root/usr.bin/ssh/xmalloc.c
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2001-02-07 08:57:27 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2001-02-07 08:57:27 +0000
commit2834e27db996b8c8b8cc05ed392bb3121da35002 (patch)
tree8658e38f676f6dbbf66d5016fd6c7c8e98a14776 /usr.bin/ssh/xmalloc.c
parent7b9c7ac8f82e111861bcfdaf5a3291c0d2cd948b (diff)
deal with new ANSI malloc stuff
Diffstat (limited to 'usr.bin/ssh/xmalloc.c')
-rw-r--r--usr.bin/ssh/xmalloc.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/usr.bin/ssh/xmalloc.c b/usr.bin/ssh/xmalloc.c
index 1a471889a34..20ccb4dc559 100644
--- a/usr.bin/ssh/xmalloc.c
+++ b/usr.bin/ssh/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.12 2001/02/07 08:57:26 deraadt Exp $");
#include "xmalloc.h"
#include "log.h"
@@ -21,7 +21,11 @@ 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);
return ptr;
@@ -32,6 +36,8 @@ xrealloc(void *ptr, size_t new_size)
{
void *new_ptr;
+ if (new_size == 0)
+ fatal("xmalloc: zero size");
if (ptr == NULL)
fatal("xrealloc: NULL pointer given as argument");
new_ptr = realloc(ptr, new_size);
@@ -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("xmalloc: zero size");
+ cp = xmalloc(len);
strlcpy(cp, str, len);
return cp;
}