[cairo-commit] 2 commits - src/cairo-malloc-private.h
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Sat Apr 17 07:06:08 UTC 2021
src/cairo-malloc-private.h | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
New commits:
commit dfd543d0134d366df6864b0ef4d4e491425ec2c9
Merge: c287fb3a1 67099a091
Author: Uli Schlachter <psychon at znc.in>
Date: Sat Apr 17 07:06:06 2021 +0000
Merge branch 'fix-cairo-malloc' into 'master'
Change int to size_t in the _cairo_malloc function family
See merge request cairo/cairo!153
commit 67099a091ec289b5190fbce4dd12ff710b8706a0
Author: Anton Danilkin <afdw at yandex.ru>
Date: Tue Apr 13 19:10:40 2021 +0200
Change int to size_t in the _cairo_malloc function family
This should allow to use them for allocating large amounts of memory.
Also use explicit checks for zeros to not make the compiler think that it is a boolean context.
diff --git a/src/cairo-malloc-private.h b/src/cairo-malloc-private.h
index 570f7cb0e..40314e1ce 100644
--- a/src/cairo-malloc-private.h
+++ b/src/cairo-malloc-private.h
@@ -60,7 +60,7 @@
**/
#define _cairo_malloc(size) \
- ((size) > 0 ? malloc((unsigned) (size)) : NULL)
+ ((size) != 0 ? malloc(size) : NULL)
/**
* _cairo_malloc_ab:
@@ -80,8 +80,8 @@
**/
#define _cairo_malloc_ab(a, size) \
- ((size) && (unsigned) (a) >= INT32_MAX / (unsigned) (size) ? NULL : \
- _cairo_malloc((unsigned) (a) * (unsigned) (size)))
+ ((size) != 0 && (size_t) (a) >= SIZE_MAX / (size_t) (size) ? NULL : \
+ _cairo_malloc((size_t) (a) * (size_t) (size)))
/**
* _cairo_realloc_ab:
@@ -102,8 +102,8 @@
**/
#define _cairo_realloc_ab(ptr, a, size) \
- ((size) && (unsigned) (a) >= INT32_MAX / (unsigned) (size) ? NULL : \
- realloc(ptr, (unsigned) (a) * (unsigned) (size)))
+ ((size) != 0 && (size_t) (a) >= SIZE_MAX / (size_t) (size) ? NULL : \
+ realloc(ptr, (size_t) (a) * (size_t) (size)))
/**
* _cairo_malloc_abc:
@@ -123,9 +123,9 @@
**/
#define _cairo_malloc_abc(a, b, 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)))
+ ((b) != 0 && (size_t) (a) >= SIZE_MAX / (size_t) (b) ? NULL : \
+ (size) != 0 && (size_t) ((a)*(b)) >= SIZE_MAX / (size_t) (size) ? NULL : \
+ _cairo_malloc((size_t) (a) * (size_t) (b) * (size_t) (size)))
/**
* _cairo_malloc_ab_plus_c:
@@ -142,8 +142,8 @@
**/
#define _cairo_malloc_ab_plus_c(a, size, c) \
- ((size) && (unsigned) (a) >= INT32_MAX / (unsigned) (size) ? NULL : \
- (unsigned) (c) >= INT32_MAX - (unsigned) (a) * (unsigned) (size) ? NULL : \
- _cairo_malloc((unsigned) (a) * (unsigned) (size) + (unsigned) (c)))
+ ((size) != 0 && (size_t) (a) >= SIZE_MAX / (size_t) (size) ? NULL : \
+ (size_t) (c) >= SIZE_MAX - (size_t) (a) * (size_t) (size) ? NULL : \
+ _cairo_malloc((size_t) (a) * (size_t) (size) + (size_t) (c)))
#endif /* CAIRO_MALLOC_PRIVATE_H */
More information about the cairo-commit
mailing list