From d1f70a3e69636f5020fb7982097e6bac6bcca290 Mon Sep 17 00:00:00 2001 From: "vladimir@pobox.com" Date: Thu, 20 Sep 2007 15:34:31 -0700 Subject: [PATCH] b=391184, accidentally blew away this patch with cairo update --- gfx/cairo/cairo/src/cairo-malloc-private.h | 35 +++++++++++++++------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/gfx/cairo/cairo/src/cairo-malloc-private.h b/gfx/cairo/cairo/src/cairo-malloc-private.h index f503b3951129..ad22851b1070 100644 --- a/gfx/cairo/cairo/src/cairo-malloc-private.h +++ b/gfx/cairo/cairo/src/cairo-malloc-private.h @@ -39,12 +39,27 @@ #include "cairo-wideint-private.h" +/** + * _cairo_malloc: + * @size: size in bytes + * + * Allocate @size memory using malloc(). + * The memory should be freed using free(). + * malloc is skipped, if 0 bytes are requested, and %NULL will be returned. + * + * Return value: A pointer to the newly allocated memory, or %NULL in + * case of malloc() failure or size is 0. + */ + +#define _cairo_malloc(size) \ + ((size) ? malloc((unsigned) (size)) : NULL) + /** * _cairo_malloc_ab: * @n: number of elements to allocate * @size: size of each element * - * Allocates @a*@size memory using malloc(), taking care to not + * Allocates @a*@size memory using _cairo_malloc(), taking care to not * overflow when doing the multiplication. Behaves much like * calloc(), except that the returned memory is not set to zero. * The memory should be freed using free(). @@ -57,8 +72,8 @@ */ #define _cairo_malloc_ab(a, size) \ - ((unsigned) (a) >= INT32_MAX / (unsigned) (size) ? NULL : \ - malloc((unsigned) (a) * (unsigned) (size))) + ((size) && (unsigned) (a) >= INT32_MAX / (unsigned) (size) ? NULL : \ + _cairo_malloc((unsigned) (a) * (unsigned) (size))) /** * _cairo_malloc_abc: @@ -66,7 +81,7 @@ * @b: second factor of number of elements to allocate * @size: size of each element * - * Allocates @a*@b*@size memory using malloc(), taking care to not + * Allocates @a*@b*@size memory using _cairo_malloc(), taking care to not * overflow when doing the multiplication. Behaves like * _cairo_malloc_ab(). The memory should be freed using free(). * @@ -78,9 +93,9 @@ */ #define _cairo_malloc_abc(a, b, size) \ - ((unsigned) (a) >= INT32_MAX / (unsigned) (b) ? NULL : \ - (unsigned) ((a)*(b)) >= INT32_MAX / (unsigned) (size) ? NULL : \ - malloc((unsigned) (a) * (unsigned) (b) * (unsigned) size)) + ((b) && (unsigned) (a) >= INT32_MAX / (unsigned) (b) ? NULL : \ + (size) && (unsigned) ((a)*(b)) >= INT32_MAX / (unsigned) (size) ? NULL : \ + _cairo_malloc((unsigned) (a) * (unsigned) (b) * (unsigned) (size))) /** * _cairo_malloc_ab_plus_c: @@ -88,7 +103,7 @@ * @size: size of each element * @k: additional size to allocate * - * Allocates @a*@ksize+@k memory using malloc(), taking care to not + * Allocates @a*@ksize+@k memory using _cairo_malloc(), taking care to not * overflow when doing the arithmetic. Behaves like * _cairo_malloc_ab(). The memory should be freed using free(). * @@ -97,8 +112,8 @@ */ #define _cairo_malloc_ab_plus_c(n, size, k) \ - ((unsigned) (n) >= INT32_MAX / (unsigned) (size) ? NULL : \ + ((size) && (unsigned) (n) >= INT32_MAX / (unsigned) (size) ? NULL : \ (unsigned) (k) >= INT32_MAX - (unsigned) (n) * (unsigned) (size) ? NULL : \ - malloc((unsigned) (n) * (unsigned) (size) + (unsigned) (k))) + _cairo_malloc((unsigned) (n) * (unsigned) (size) + (unsigned) (k))) #endif /* CAIRO_MALLOC_PRIVATE_H */