diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2007-12-27 10:45:25 +0000 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2007-12-27 10:45:25 +0000 |
commit | d8169b8cef041b4dbcea44e050df28659f4846aa (patch) | |
tree | db06f129fe7dd9c6cf90be67b41a0ea82b162756 /src/cairo-path-fixed.c | |
parent | 7f69c2588b33d415f544c2ee24d85c83a8d7cd69 (diff) |
[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.
Diffstat (limited to 'src/cairo-path-fixed.c')
-rw-r--r-- | src/cairo-path-fixed.c | 9 |
1 files 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; } |