Fix for potential unaligned memory accesses
authorSiarhei Siamashka <siarhei.siamashka@nokia.com>
Mon, 29 Nov 2010 22:31:06 +0000 (00:31 +0200)
committerSiarhei Siamashka <siarhei.siamashka@nokia.com>
Tue, 7 Dec 2010 00:10:51 +0000 (02:10 +0200)
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

index 4d234a0..8130f16 100644 (file)
@@ -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);
 }