From eacb9e98581131eacdee13a4941c239e733f4361 Mon Sep 17 00:00:00 2001 From: Alex Cherepanov Date: Fri, 14 Dec 2007 18:31:39 +0000 Subject: Align the pointer to gx_clist_state array in gx_device_clist_writer device to the natural boundary to avoid misaligned memory access and bus errors on ARM processors. Bug 689600. DIFFERENCES: None git-svn-id: http://svn.ghostscript.com/ghostscript/trunk@8440 a1074d23-0009-0410-80fe-cf8c14f379e6 --- gs/src/gxclist.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gs/src/gxclist.c b/gs/src/gxclist.c index f1fd816b5..65e887650 100644 --- a/gs/src/gxclist.c +++ b/gs/src/gxclist.c @@ -309,17 +309,21 @@ clist_init_states(gx_device * dev, byte * init_data, uint data_size) gx_device_clist_writer * const cdev = &((gx_device_clist *)dev)->writer; ulong state_size = cdev->nbands * (ulong) sizeof(gx_clist_state); + /* Align to the natural boundary for ARM processors, bug 689600 */ + long alignment = (-(long)init_data) & (sizeof(init_data) - 1); /* * The +100 in the next line is bogus, but we don't know what the * real check should be. We're effectively assuring that at least 100 * bytes will be available to buffer command operands. */ - if (state_size + sizeof(cmd_prefix) + cmd_largest_size + 100 > data_size) + if (state_size + sizeof(cmd_prefix) + cmd_largest_size + 100 + alignment > data_size) return_error(gs_error_rangecheck); + /* The end buffer position is not affected by alignment */ + cdev->cend = init_data + data_size; + init_data += alignment; cdev->states = (gx_clist_state *) init_data; cdev->cbuf = init_data + state_size; - cdev->cend = init_data + data_size; return 0; } -- cgit v1.2.3