diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2008-04-07 10:51:27 +0100 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2008-04-08 07:52:46 +0100 |
commit | e57ef66fab7cb05b84175b3cfb5c032150cfa682 (patch) | |
tree | 20f02e9872e4465ce512edeef3b98e37e22f6364 | |
parent | d0672e85ef120a4e3cd0dfcbdb717afbf9526f17 (diff) |
[test/xlib-surface] Zero pixel buffers before use.
As we only use RGB24 surface data the alpha channel is undefined, so
zero it to prevent valgrind warnings.
-rw-r--r-- | test/xlib-surface.c | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/test/xlib-surface.c b/test/xlib-surface.c index d95834988..deb288970 100644 --- a/test/xlib-surface.c +++ b/test/xlib-surface.c @@ -210,6 +210,19 @@ check_visual (Display *dpy) return 0; } +#undef xcalloc +static void * +xcalloc (size_t a, size_t b) +{ + void *ptr = calloc (a, b); + if (ptr == NULL) { + cairo_test_log ("xlib-surface: unable to allocate memory, skipping\n"); + cairo_test_fini (); + exit (0); + } + return ptr; +} + int main (void) { @@ -222,6 +235,7 @@ main (void) cairo_bool_t set_size; cairo_bool_t offscreen; cairo_test_status_t status, result = CAIRO_TEST_SUCCESS; + int stride; cairo_test_init ("xlib-surface"); @@ -238,14 +252,16 @@ main (void) return 0; } - reference_data = malloc (SIZE * SIZE * 4); - test_data = malloc (SIZE * SIZE * 4); - diff_data = malloc (SIZE * SIZE * 4); + stride = cairo_format_stride_for_width (CAIRO_FORMAT_RGB24, SIZE); + + reference_data = xcalloc (SIZE, stride); + test_data = xcalloc (SIZE, stride); + diff_data = xcalloc (SIZE, stride); reference_surface = cairo_image_surface_create_for_data (reference_data, CAIRO_FORMAT_RGB24, SIZE, SIZE, - SIZE * 4); + stride); draw_pattern (reference_surface); cairo_surface_destroy (reference_surface); |