From 7332a5e9949ca19869b003fe5a0a777adac41307 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Wed, 27 Jun 2007 11:32:50 +0100 Subject: [PATCH] [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. --- boilerplate/xmalloc.c | 6 +++--- src/cairo-image-surface.c | 2 +- 2 files changed, 4 insertions(+), 4 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); } diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c index b9c4748e7..553433c8a 100644 --- a/src/cairo-image-surface.c +++ b/src/cairo-image-surface.c @@ -922,7 +922,7 @@ _cairo_image_surface_composite_trapezoids (cairo_operator_t op, } /* Special case adding trapezoids onto a mask surface; we want to avoid - * creating an intermediate temporary mask unecessarily. + * creating an intermediate temporary mask unnecessarily. * * We make the assumption here that the portion of the trapezoids * contained within the surface is bounded by [dst_x,dst_y,width,height];