From: Siarhei Siamashka Date: Mon, 29 Nov 2010 22:31:06 +0000 (+0200) Subject: Fix for potential unaligned memory accesses X-Git-Tag: 1.0_branch~383 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3d094997b1820719d15cec7dc633ed37e1912bfc;p=profile%2Fivi%2Fpixman.git 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 --- 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); }