mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-05-04 23:28:07 +02:00
[memfault] Manually inject faults when using stack allocations
Ensure that no assumptions are made that a small allocation will succeed by manually injecting faults when we may be simply allocating from an embedded memory pool. The main advantage in manual fault injection is improved code coverage - from within the test suite most allocations are handled by the embedded memory pools.
This commit is contained in:
parent
817589e196
commit
1ae2ddc1dd
14 changed files with 64 additions and 0 deletions
|
|
@ -125,6 +125,9 @@ _cairo_array_grow_by (cairo_array_t *array, unsigned int additional)
|
|||
if (required_size > INT_MAX || required_size < array->num_elements)
|
||||
return _cairo_error (CAIRO_STATUS_NO_MEMORY);
|
||||
|
||||
if (CAIRO_INJECT_FAULT ())
|
||||
return _cairo_error (CAIRO_STATUS_NO_MEMORY);
|
||||
|
||||
if (required_size <= old_size)
|
||||
return CAIRO_STATUS_SUCCESS;
|
||||
|
||||
|
|
|
|||
|
|
@ -1660,6 +1660,9 @@ _cairo_bentley_ottmann_tessellate_polygon (cairo_traps_t *traps,
|
|||
if (0 == polygon->num_edges)
|
||||
return CAIRO_STATUS_SUCCESS;
|
||||
|
||||
if (CAIRO_INJECT_FAULT ())
|
||||
return _cairo_error (CAIRO_STATUS_NO_MEMORY);
|
||||
|
||||
has_limits = _cairo_traps_get_limit (traps, &limit);
|
||||
|
||||
edges = stack_edges;
|
||||
|
|
|
|||
|
|
@ -222,6 +222,9 @@ _cairo_gstate_save (cairo_gstate_t **gstate, cairo_gstate_t **freelist)
|
|||
cairo_gstate_t *top;
|
||||
cairo_status_t status;
|
||||
|
||||
if (CAIRO_INJECT_FAULT ())
|
||||
return _cairo_error (CAIRO_STATUS_NO_MEMORY);
|
||||
|
||||
top = *freelist;
|
||||
if (top == NULL) {
|
||||
top = malloc (sizeof (cairo_gstate_t));
|
||||
|
|
|
|||
|
|
@ -198,6 +198,9 @@ _cairo_hull_compute (cairo_pen_vertex_t *vertices, int *num_vertices)
|
|||
cairo_hull_t *hull;
|
||||
int num_hull = *num_vertices;
|
||||
|
||||
if (CAIRO_INJECT_FAULT ())
|
||||
return _cairo_error (CAIRO_STATUS_NO_MEMORY);
|
||||
|
||||
if (num_hull > ARRAY_LENGTH (hull_stack)) {
|
||||
hull = _cairo_malloc_ab (num_hull, sizeof (cairo_hull_t));
|
||||
if (unlikely (hull == NULL))
|
||||
|
|
|
|||
|
|
@ -1044,6 +1044,9 @@ _cairo_image_surface_fill_rectangles (void *abstract_surface,
|
|||
|
||||
cairo_int_status_t status = CAIRO_STATUS_SUCCESS;
|
||||
|
||||
if (CAIRO_INJECT_FAULT ())
|
||||
return _cairo_error (CAIRO_STATUS_NO_MEMORY);
|
||||
|
||||
pixman_color.red = color->red_short;
|
||||
pixman_color.green = color->green_short;
|
||||
pixman_color.blue = color->blue_short;
|
||||
|
|
@ -1112,6 +1115,9 @@ _cairo_image_surface_composite_trapezoids (cairo_operator_t op,
|
|||
if (height == 0 || width == 0)
|
||||
return CAIRO_STATUS_SUCCESS;
|
||||
|
||||
if (CAIRO_INJECT_FAULT ())
|
||||
return _cairo_error (CAIRO_STATUS_NO_MEMORY);
|
||||
|
||||
/* Convert traps to pixman traps */
|
||||
if (num_traps > ARRAY_LENGTH (stack_traps)) {
|
||||
pixman_traps = _cairo_malloc_ab (num_traps, sizeof (pixman_trapezoid_t));
|
||||
|
|
|
|||
|
|
@ -39,6 +39,13 @@
|
|||
|
||||
#include "cairo-wideint-private.h"
|
||||
|
||||
#if HAVE_MEMFAULT
|
||||
#include <memfault.h>
|
||||
#define CAIRO_INJECT_FAULT() VALGRIND_INJECT_FAULT()
|
||||
#else
|
||||
#define CAIRO_INJECT_FAULT() 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* _cairo_malloc:
|
||||
* @size: size in bytes
|
||||
|
|
|
|||
|
|
@ -704,6 +704,9 @@ _cairo_intern_string (const char **str_inout, int len)
|
|||
cairo_intern_string_t tmpl, *istring;
|
||||
cairo_status_t status = CAIRO_STATUS_SUCCESS;
|
||||
|
||||
if (CAIRO_INJECT_FAULT ())
|
||||
return _cairo_error (CAIRO_STATUS_NO_MEMORY);
|
||||
|
||||
if (len < 0)
|
||||
len = strlen (str);
|
||||
tmpl.hash_entry.hash = _intern_string_hash (str, len);
|
||||
|
|
|
|||
|
|
@ -1278,6 +1278,8 @@ _cairo_rectilinear_stroker_add_segment (cairo_rectilinear_stroker_t *stroker,
|
|||
cairo_bool_t is_horizontal,
|
||||
cairo_bool_t has_join)
|
||||
{
|
||||
if (CAIRO_INJECT_FAULT ())
|
||||
return _cairo_error (CAIRO_STATUS_NO_MEMORY);
|
||||
|
||||
if (stroker->num_segments == stroker->segments_size) {
|
||||
int new_size = stroker->segments_size * 2;
|
||||
|
|
|
|||
|
|
@ -119,6 +119,9 @@ static cairo_status_t
|
|||
_cairo_gradient_pattern_init_copy (cairo_gradient_pattern_t *pattern,
|
||||
const cairo_gradient_pattern_t *other)
|
||||
{
|
||||
if (CAIRO_INJECT_FAULT ())
|
||||
return _cairo_error (CAIRO_STATUS_NO_MEMORY);
|
||||
|
||||
if (other->base.type == CAIRO_PATTERN_TYPE_LINEAR)
|
||||
{
|
||||
cairo_linear_pattern_t *dst = (cairo_linear_pattern_t *) pattern;
|
||||
|
|
@ -841,6 +844,9 @@ _cairo_pattern_gradient_grow (cairo_gradient_pattern_t *pattern)
|
|||
return CAIRO_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
if (CAIRO_INJECT_FAULT ())
|
||||
return _cairo_error (CAIRO_STATUS_NO_MEMORY);
|
||||
|
||||
assert (pattern->n_stops <= pattern->stops_size);
|
||||
|
||||
if (pattern->stops == pattern->stops_embedded) {
|
||||
|
|
@ -1257,6 +1263,9 @@ _cairo_pattern_acquire_surface_for_gradient (const cairo_gradient_pattern_t *pat
|
|||
int clone_offset_x, clone_offset_y;
|
||||
cairo_matrix_t matrix = pattern->base.matrix;
|
||||
|
||||
if (CAIRO_INJECT_FAULT ())
|
||||
return _cairo_error (CAIRO_STATUS_NO_MEMORY);
|
||||
|
||||
if (pattern->n_stops > ARRAY_LENGTH(pixman_stops_static)) {
|
||||
pixman_stops = _cairo_malloc_ab (pattern->n_stops,
|
||||
sizeof(pixman_gradient_stop_t));
|
||||
|
|
|
|||
|
|
@ -55,6 +55,9 @@ _cairo_pen_init (cairo_pen_t *pen,
|
|||
int i;
|
||||
int reflect;
|
||||
|
||||
if (CAIRO_INJECT_FAULT ())
|
||||
return _cairo_error (CAIRO_STATUS_NO_MEMORY);
|
||||
|
||||
pen->radius = radius;
|
||||
pen->tolerance = tolerance;
|
||||
|
||||
|
|
@ -109,6 +112,9 @@ _cairo_pen_init_copy (cairo_pen_t *pen, const cairo_pen_t *other)
|
|||
{
|
||||
*pen = *other;
|
||||
|
||||
if (CAIRO_INJECT_FAULT ())
|
||||
return _cairo_error (CAIRO_STATUS_NO_MEMORY);
|
||||
|
||||
pen->vertices = pen->vertices_embedded;
|
||||
if (pen->num_vertices) {
|
||||
if (pen->num_vertices > ARRAY_LENGTH (pen->vertices_embedded)) {
|
||||
|
|
@ -132,6 +138,9 @@ _cairo_pen_add_points (cairo_pen_t *pen, cairo_point_t *point, int num_points)
|
|||
int num_vertices;
|
||||
int i;
|
||||
|
||||
if (CAIRO_INJECT_FAULT ())
|
||||
return _cairo_error (CAIRO_STATUS_NO_MEMORY);
|
||||
|
||||
num_vertices = pen->num_vertices + num_points;
|
||||
if (num_vertices > ARRAY_LENGTH (pen->vertices_embedded) ||
|
||||
pen->vertices != pen->vertices_embedded)
|
||||
|
|
|
|||
|
|
@ -64,6 +64,11 @@ _cairo_polygon_grow (cairo_polygon_t *polygon)
|
|||
int old_size = polygon->edges_size;
|
||||
int new_size = 4 * old_size;
|
||||
|
||||
if (CAIRO_INJECT_FAULT ()) {
|
||||
polygon->status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (polygon->edges == polygon->edges_embedded) {
|
||||
new_edges = _cairo_malloc_ab (new_size, sizeof (cairo_edge_t));
|
||||
if (new_edges != NULL)
|
||||
|
|
|
|||
|
|
@ -2558,6 +2558,9 @@ _cairo_scaled_glyph_lookup (cairo_scaled_font_t *scaled_font,
|
|||
if (unlikely (scaled_font->status))
|
||||
return scaled_font->status;
|
||||
|
||||
if (CAIRO_INJECT_FAULT ())
|
||||
return _cairo_error (CAIRO_STATUS_NO_MEMORY);
|
||||
|
||||
/*
|
||||
* Check cache for glyph
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -52,6 +52,9 @@ cairo_status_t
|
|||
_cairo_stroke_style_init_copy (cairo_stroke_style_t *style,
|
||||
cairo_stroke_style_t *other)
|
||||
{
|
||||
if (CAIRO_INJECT_FAULT ())
|
||||
return _cairo_error (CAIRO_STATUS_NO_MEMORY);
|
||||
|
||||
style->line_width = other->line_width;
|
||||
style->line_cap = other->line_cap;
|
||||
style->line_join = other->line_join;
|
||||
|
|
|
|||
|
|
@ -131,6 +131,11 @@ _cairo_traps_grow (cairo_traps_t *traps)
|
|||
cairo_trapezoid_t *new_traps;
|
||||
int new_size = 2 * MAX (traps->traps_size, 16);
|
||||
|
||||
if (CAIRO_INJECT_FAULT ()) {
|
||||
traps->status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (traps->traps == traps->traps_embedded) {
|
||||
new_traps = _cairo_malloc_ab (new_size, sizeof (cairo_trapezoid_t));
|
||||
if (new_traps != NULL)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue