/** * _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.
**/
/** * _cairo_malloc_ab: * @a: number of elements to allocate * @size: size of each element * * 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(). * * @size should be a constant so that the compiler can optimize * out a constant division. * * Return value: A pointer to the newly allocated memory, or %NULL in * case of malloc() failure or overflow.
**/
static cairo_always_inline void *
_cairo_malloc_ab(size_t a, size_t size)
{
size_t c; if (_cairo_mul_size_t_overflow (a, size, &c)) return NULL;
return _cairo_malloc(c);
}
/** * _cairo_realloc_ab: * @ptr: original pointer to block of memory to be resized * @a: number of elements to allocate * @size: size of each element * * Reallocates @ptr a block of @a*@size memory using realloc(), taking * care to not overflow when doing the multiplication. The memory * should be freed using free(). * * @size should be a constant so that the compiler can optimize * out a constant division. * * Return value: A pointer to the newly allocated memory, or %NULL in * case of realloc() failure or overflow (whereupon the original block * of memory * is left untouched).
**/
static cairo_always_inline void *
_cairo_realloc_ab(void *ptr, size_t a, size_t size)
{
size_t c; if (_cairo_mul_size_t_overflow (a, size, &c)) return NULL;
return realloc(ptr, c);
}
/** * _cairo_malloc_abc: * @a: first factor of number of elements to allocate * @b: second factor of number of elements to allocate * @size: size of each element * * 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(). * * @size should be a constant so that the compiler can optimize * out a constant division. * * Return value: A pointer to the newly allocated memory, or %NULL in * case of malloc() failure or overflow.
**/
if (_cairo_mul_size_t_overflow (c, size, &d)) return NULL;
return _cairo_malloc(d);
}
/** * _cairo_malloc_ab_plus_c: * @a: number of elements to allocate * @size: size of each element * @c: additional size to allocate * * Allocates @a*@size+@c memory using _cairo_malloc(), taking care to not * overflow when doing the arithmetic. Behaves similar to * _cairo_malloc_ab(). The memory should be freed using free(). * * Return value: A pointer to the newly allocated memory, or %NULL in * case of malloc() failure or overflow.
**/
static cairo_always_inline void *
_cairo_malloc_ab_plus_c(size_t a, size_t size, size_t c)
{
size_t d, e; if (_cairo_mul_size_t_overflow (a, size, &d)) return NULL;
if (_cairo_add_size_t_overflow (d, c, &e)) return NULL;
return _cairo_malloc(e);
}
#endif/* CAIRO_MALLOC_PRIVATE_H */
Messung V0.5
¤ Dauer der Verarbeitung: 0.24 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.