[Gs-code-review] Fix for bug #523073 "Segment fault in mem_mono_copy_mono".
Igor V. Melichev
igor at artifex.com
Wed Feb 27 02:36:06 PST 2002
[Log message beg]
FAPI project : An unaligned bitmap was passed from UFST to
mem_mono_copy_mono.
Creating a temporary aligned copy on necessity.
Source Forge bug #523073 "Segment fault in mem_mono_copy_mono".
[Log message end]
This is post-commit submission.
It only changes UFST-dependent files.
Perhaps at least for Intel/Windows the alignment constraint may be replaced
with a weaker one. Intel hardware doesn't require an alignment.
Therefore only the last line needs to be padded to word boundary.
With this weaker constraint the temporary copy is needed
for lesser cases. If even and odd bitmap size has same probability
for both width and height, the average number of copies would be 4 times
lesser.
Changes:
File fapiufst.c :
*** f:\casper\head\gs\src\fapiufst.c Mon Feb 25 20:21:09 2002
--- files\gs\src\fapiufst.c Wed Feb 27 12:30:45 2002
***************
*** 858,862 ****
if (code == ERR_find_cgnum) {
/* There is no such char in the font, try the glyph 0 (notdef) :
*/
! void *client_char_data = ff->client_char_data;
UW16 c1 = 0, ssnum = r->IFS.fcCur.ssnum;
/* hack : Changing UFST internal data - see above. */
--- 858,862 ----
if (code == ERR_find_cgnum) {
/* There is no such char in the font, try the glyph 0 (notdef) :
*/
! const void *client_char_data = ff->client_char_data;
UW16 c1 = 0, ssnum = r->IFS.fcCur.ssnum;
/* hack : Changing UFST internal data - see above. */
***************
*** 920,924 ****
if (!r->bRaster)
return e_limitcheck;
! else if (r->char_data != NULL) {
IFBITMAP *pbm = (IFBITMAP *)r->char_data;
rast->p = pbm->bm;
--- 920,927 ----
if (!r->bRaster)
return e_limitcheck;
! else if (r->char_data == NULL) {
! rast->height = rast->width = rast->line_step = 0;
! rast->p = 0;
! } else {
IFBITMAP *pbm = (IFBITMAP *)r->char_data;
rast->p = pbm->bm;
File zfapi.c :
*** f:\casper\head\gs\src\zfapi.c Mon Feb 25 20:21:09 2002
--- files\gs\src\zfapi.c Wed Feb 27 12:36:00 2002
***************
*** 885,888 ****
--- 885,905 ----
}
+ private int fapi_copy_mono(gx_device *dev1, FAPI_raster *rast, int dx, int
dy)
+ { if ((rast->line_step & (align_bitmap_mod - 1)) == 0)
+ return dev_proc(dev1, copy_mono)(dev1, rast->p, 0,
rast->line_step, 0, dx, dy, rast->width, rast->height, 0, 1);
+ else { /* bitmap data needs to be aligned, make the aligned copy : */
+ int line_step = bitmap_raster(rast->width), code;
+ byte *p = gs_alloc_byte_array(dev1->memory, rast->height,
line_step, "fapi_copy_mono");
+ byte *q = p, *r = rast->p, *pe;
+ if (p == NULL)
+ return_error(e_VMerror);
+ pe = p + rast->height * line_step;
+ for (; q < pe; q+=line_step, r += rast->line_step)
+ memcpy(q, r, rast->line_step);
+ code = dev_proc(dev1, copy_mono)(dev1, p, 0, line_step, 0, dx, dy,
rast->width, rast->height, 0, 1);
+ gs_free_object(dev1->memory, p, "fapi_copy_mono");
+ return code;
+ }
+ }
private const int frac_pixel_shift = 4;
***************
*** 927,931 ****
int dx = arith_rshift_slow((pgs->ctm.tx_fixed >> shift_rd)
+ rast.orig_x + rounding, frac_pixel_shift);
int dy = arith_rshift_slow((pgs->ctm.ty_fixed >>
shift_rd) - rast.orig_y + rounding, frac_pixel_shift);
! return_if_error(dev_proc(dev1, copy_mono)(dev1, rast.p, 0,
rast.line_step, 0, dx, dy, rast.width, rast.height, 0, 1));
} else { /* Not using GS cache */
const gx_clip_path * pcpath = i_ctx_p->pgs->clip_path;
--- 944,948 ----
int dx = arith_rshift_slow((pgs->ctm.tx_fixed >> shift_rd)
+ rast.orig_x + rounding, frac_pixel_shift);
int dy = arith_rshift_slow((pgs->ctm.ty_fixed >>
shift_rd) - rast.orig_y + rounding, frac_pixel_shift);
! return_if_error(fapi_copy_mono(dev1, &rast, dx, dy));
} else { /* Not using GS cache */
const gx_clip_path * pcpath = i_ctx_p->pgs->clip_path;
More information about the gs-code-review
mailing list