From d8169b8cef041b4dbcea44e050df28659f4846aa Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Thu, 27 Dec 2007 10:45:25 +0000 Subject: [PATCH] [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. --- src/cairo-path-fixed.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/cairo-path-fixed.c b/src/cairo-path-fixed.c index ad738452f..d48536410 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; }