diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2007-06-27 11:32:50 +0100 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2007-08-16 15:36:05 +0100 |
commit | 7332a5e9949ca19869b003fe5a0a777adac41307 (patch) | |
tree | 7e261d6c6115cd1b59d0c16c087f3831130890e6 /boilerplate | |
parent | 56e505298c0f5de360380ca7e968baa0e60ac828 (diff) |
[boilerplate/xmalloc] Special case malloc(0) and friends.
malloc(0) can return NULL so double check the requested size before
exiting with an out-of-memory error.
Diffstat (limited to 'boilerplate')
-rw-r--r-- | boilerplate/xmalloc.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/boilerplate/xmalloc.c b/boilerplate/xmalloc.c index ddd5cccaf..c2cbe2321 100644 --- a/boilerplate/xmalloc.c +++ b/boilerplate/xmalloc.c @@ -36,7 +36,7 @@ xmalloc (size_t size) void *buf; buf = malloc (size); - if (!buf) { + if (buf == NULL && size != 0) { CAIRO_BOILERPLATE_LOG ("Error: Out of memory. Exiting.\n"); exit (1); } @@ -50,7 +50,7 @@ xcalloc (size_t nmemb, size_t size) void *buf; buf = calloc (nmemb, size); - if (!buf) { + if (buf == NULL && nmemb != 0 && size != 0) { CAIRO_BOILERPLATE_LOG ("Error: Out of memory. Exiting\n"); exit (1); } @@ -62,7 +62,7 @@ void * xrealloc (void *buf, size_t size) { buf = realloc (buf, size); - if (!buf) { + if (buf == NULL && size != 0) { CAIRO_BOILERPLATE_LOG ("Error: Out of memory. Exiting\n"); exit (1); } |