[cairo-commit] src/cairo-path-fixed.c
Chris Wilson
ickle at kemper.freedesktop.org
Thu Dec 27 02:53:04 PST 2007
src/cairo-path-fixed.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
New commits:
commit d8169b8cef041b4dbcea44e050df28659f4846aa
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Thu Dec 27 10:45:25 2007 +0000
[cairo-path-fixed] Ensure the array of points is correctly aligned.
In http://bugs.gentoo.org/show_bug.cgi?id=203282, it was identified that
the cairo_path_buf was causing unaligned accesses (thus generating SIGBUS
on architectures like the SPARC) to its array of points. As we manually
allocate a single block of memory for the cairo_path_buf_t and its
arrays, we must also manually ensure correct alignment - as opposed to
cairo_path_buf_fixed_t for which the compiler automatically aligns the
embedded arrays.
diff --git a/src/cairo-path-fixed.c b/src/cairo-path-fixed.c
index ad73845..d485364 100644
--- a/src/cairo-path-fixed.c
+++ b/src/cairo-path-fixed.c
@@ -404,10 +404,12 @@ _cairo_path_buf_create (int buf_size)
{
cairo_path_buf_t *buf;
+#define align(ptr__, alignment__) \
+ ((void *) (((long) (ptr__) + (alignment__) - 1) & -(alignment__)))
buf = _cairo_malloc_ab_plus_c (buf_size,
sizeof (cairo_path_op_t) +
2 * sizeof (cairo_point_t),
- sizeof (cairo_path_buf_t));
+ sizeof (cairo_path_buf_t) + sizeof (double));
if (buf) {
buf->next = NULL;
buf->prev = NULL;
@@ -415,9 +417,10 @@ _cairo_path_buf_create (int buf_size)
buf->num_points = 0;
buf->buf_size = buf_size;
- buf->op = (cairo_path_op_t *) (buf + 1);
- buf->points = (cairo_point_t *) (buf->op + buf_size);
+ buf->points = (cairo_point_t *) align (buf + 1, sizeof (double));
+ buf->op = (cairo_path_op_t *) (buf->points + 2 * buf_size);
}
+#undef align
return buf;
}
More information about the cairo-commit
mailing list