From 3d094997b1820719d15cec7dc633ed37e1912bfc Mon Sep 17 00:00:00 2001 From: Siarhei Siamashka Date: Tue, 30 Nov 2010 00:31:06 +0200 Subject: [PATCH] Fix for potential unaligned memory accesses The temporary scanline buffer allocated on stack was declared as uint8_t array. As a result, the compiler was free to select any arbitrary alignment for it (even though there is typically no reason to use really weird alignments here and the stack is normally at least 4 bytes aligned on most platforms). Having improper alignment is non-portable and can impact performance or even make the code misbehave depending on the target platform. Using uint64_t type for this array should ensure that any possible memory accesses done by pixman code are going to be handled correctly (pixman-combine64.c can access this buffer via uint64_t * pointer). Some alignment related problem was reported in: http://lists.freedesktop.org/archives/pixman/2010-November/000747.html --- pixman/pixman-general.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pixman/pixman-general.c b/pixman/pixman-general.c index 4d234a0..8130f16 100644 --- a/pixman/pixman-general.c +++ b/pixman/pixman-general.c @@ -56,8 +56,8 @@ general_composite_rect (pixman_implementation_t *imp, int32_t width, int32_t height) { - uint8_t stack_scanline_buffer[SCANLINE_BUFFER_LENGTH * 3]; - uint8_t *scanline_buffer = stack_scanline_buffer; + uint64_t stack_scanline_buffer[(SCANLINE_BUFFER_LENGTH * 3 + 7) / 8]; + uint8_t *scanline_buffer = (uint8_t *) stack_scanline_buffer; uint8_t *src_buffer, *mask_buffer, *dest_buffer; fetch_scanline_t fetch_src = NULL, fetch_mask = NULL, fetch_dest = NULL; pixman_combine_32_func_t compose; @@ -255,7 +255,7 @@ general_composite_rect (pixman_implementation_t *imp, } } - if (scanline_buffer != stack_scanline_buffer) + if (scanline_buffer != (uint8_t *) stack_scanline_buffer) free (scanline_buffer); } -- 2.7.4