summaryrefslogtreecommitdiff
path: root/xmalloc.c
diff options
context:
space:
mode:
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 1a471889a..8a23b8b70 100644
--- a/xmalloc.c
+++ b/xmalloc.c
@@ -13,7 +13,7 @@
13 */ 13 */
14 14
15#include "includes.h" 15#include "includes.h"
16RCSID("$OpenBSD: xmalloc.c,v 1.11 2001/02/04 15:32:27 stevesk Exp $"); 16RCSID("$OpenBSD: xmalloc.c,v 1.14 2001/02/07 18:04:50 itojun Exp $");
17 17
18#include "xmalloc.h" 18#include "xmalloc.h"
19#include "log.h" 19#include "log.h"
@@ -21,9 +21,13 @@ RCSID("$OpenBSD: xmalloc.c,v 1.11 2001/02/04 15:32:27 stevesk Exp $");
21void * 21void *
22xmalloc(size_t size) 22xmalloc(size_t size)
23{ 23{
24 void *ptr = malloc(size); 24 void *ptr;
25
26 if (size == 0)
27 fatal("xmalloc: zero size");
28 ptr = malloc(size);
25 if (ptr == NULL) 29 if (ptr == NULL)
26 fatal("xmalloc: out of memory (allocating %d bytes)", (int) size); 30 fatal("xmalloc: out of memory (allocating %lu bytes)", (u_long) size);
27 return ptr; 31 return ptr;
28} 32}
29 33
@@ -32,11 +36,13 @@ xrealloc(void *ptr, size_t new_size)
32{ 36{
33 void *new_ptr; 37 void *new_ptr;
34 38
39 if (new_size == 0)
40 fatal("xrealloc: zero size");
35 if (ptr == NULL) 41 if (ptr == NULL)
36 fatal("xrealloc: NULL pointer given as argument"); 42 fatal("xrealloc: NULL pointer given as argument");
37 new_ptr = realloc(ptr, new_size); 43 new_ptr = realloc(ptr, new_size);
38 if (new_ptr == NULL) 44 if (new_ptr == NULL)
39 fatal("xrealloc: out of memory (new_size %d bytes)", (int) new_size); 45 fatal("xrealloc: out of memory (new_size %lu bytes)", (u_long) new_size);
40 return new_ptr; 46 return new_ptr;
41} 47}
42 48
@@ -52,8 +58,11 @@ char *
52xstrdup(const char *str) 58xstrdup(const char *str)
53{ 59{
54 size_t len = strlen(str) + 1; 60 size_t len = strlen(str) + 1;
61 char *cp;
55 62
56 char *cp = xmalloc(len); 63 if (len == 0)
64 fatal("xstrdup: zero size");
65 cp = xmalloc(len);
57 strlcpy(cp, str, len); 66 strlcpy(cp, str, len);
58 return cp; 67 return cp;
59} 68}