diff options
author | Carl Worth <cworth@cworth.org> | 2008-02-16 13:27:02 -0800 |
---|---|---|
committer | Carl Worth <cworth@cworth.org> | 2008-02-20 04:04:04 -0800 |
commit | d6d81c92b501b32be6c48d134683ebd51f63c134 (patch) | |
tree | 4c9a1c0e676e29fb29bec39897d32107e6c3a51b /src/cairo-pen.c | |
parent | 770b058c9e53c6d0e3a3f600cd5a9631eee39dff (diff) | |
download | cairo-d6d81c92b501b32be6c48d134683ebd51f63c134.tar.gz |
Eliminate a potential infinite loop in spline stroking
Sometimes > rather than >= can make a bug difference. The infinite loop
was noticed here:
Infinite loop when scaling very small values using 24.8
http://bugs.freedesktop.org/show_bug.cgi?id=14280
Note that that particular test case only exposes the infinite
loop when using 24.8 instead of 16.16 fixed-point values by
setting CAIRO_FIXED_FRAC_BITS to 8.
Diffstat (limited to 'src/cairo-pen.c')
-rw-r--r-- | src/cairo-pen.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/cairo-pen.c b/src/cairo-pen.c index fc01970f2..37456d99f 100644 --- a/src/cairo-pen.c +++ b/src/cairo-pen.c @@ -417,7 +417,18 @@ _cairo_pen_stroke_spline_half (cairo_pen_t *pen, slope = final_slope; else _cairo_slope_init (&slope, &point[i], &point[i+step]); - if (_cairo_slope_compare (&slope, &pen->vertices[active].slope_ccw) >= 0) { + + /* The strict inequalities here ensure that if a spline slope + * compares identically with either of the slopes of the + * active vertex, then it remains the active vertex. This is + * very important since otherwise we can trigger an infinite + * loop in the case of a degenerate pen, (a line), where + * neither vertex considers itself active for the slope---one + * will consider it as equal and reject, and the other will + * consider it unequal and reject. This is due to the inherent + * ambiguity when comparing slopes that differ by exactly + * pi. */ + if (_cairo_slope_compare (&slope, &pen->vertices[active].slope_ccw) > 0) { if (++active == pen->num_vertices) active = 0; } else if (_cairo_slope_compare (&slope, &pen->vertices[active].slope_cw) < 0) { |