[cairo] FP errors in cairo

John Ellson ellson at research.att.com
Sun May 1 20:17:54 PDT 2005


I'm  getting lots of cairo crashes in my application (graphviz) on 32 
bit machines, but less or none on 64 bit machines. 
I'm a bit surprised that other cairo users aren't seeing problems?  
Perhaps graphviz just generates more curves than other apps.
A gdb tracback is attached.

I think that the problem is that this code is not robust:

cairo-traps.c:557
    cairo_fixed_16_16_t y_intersect;
    double  m1 = _compute_inverse_slope (l1);
    double  b1 = _compute_x_intercept (l1, m1);
    double  m2 = _compute_inverse_slope (l2);
    double  b2 = _compute_x_intercept (l2, m2);

    if (m1 == m2)
        return 0;

    y_intersect = _cairo_fixed_from_double ((b2 - b1) / (m1 - m2));

The m1 == m2 test is not sufficient to prevent integer overflows on 32 
bit machines.

I see from the comments that there are other concerns about this code.   
Is there a rewite in the works
or should I take a shot at improving the stability of this version?

John

----------------------------------------------

Program received signal SIGFPE, Arithmetic exception.
0x001799df in _cairo_fixed_from_double (d=-95136.092880705997)
    at cairo-fixed.c:48
48          return (cairo_fixed_t) (d * 65536);
(gdb) where
#0  0x001799df in _cairo_fixed_from_double (d=-95136.092880705997)
    at cairo-fixed.c:48
#1  0x00183dd8 in _line_segs_intersect_ceil (l1=0x91be878, l2=0x91be890,
    y_ret=0x520c78) at cairo-traps.c:566
#2  0x00183fbf in _cairo_traps_tessellate_polygon (traps=0xbfeca630,
    poly=0x520c78, fill_rule=CAIRO_FILL_RULE_WINDING) at cairo-traps.c:689
#3  0x00181e91 in _cairo_pen_stroke_spline (pen=0xbfeca420, 
spline=0xbfeca440,
    tolerance=0.10000000000000001, traps=0xbfeca630) at cairo-pen.c:585
#4  0x001813f1 in _cairo_stroker_curve_to (closure=0xbfeca550, b=0xbfeca4e0,
    c=0xbfeca4e8, d=0xbfeca4f0) at cairo-path-stroke.c:756
#5  0x0017f542 in _cairo_path_fixed_interpret (path=0x0,
    dir=CAIRO_DIRECTION_FORWARD, move_to=0x180c80 <_cairo_stroker_move_to>,
    line_to=0x180cbc <_cairo_stroker_line_to>,
    curve_to=0x1811b8 <_cairo_stroker_curve_to>,
    close_path=0x18142c <_cairo_stroker_close_path>, closure=0xbfeca550)
    at cairo-path.c:510
#6  0x00181519 in _cairo_path_fixed_stroke_to_traps (path=0x91b26a8,
    gstate=0x91b6658, traps=0xbfeca630) at cairo-path-stroke.c:809
#7  0x0017ba3a in _cairo_gstate_stroke (gstate=0x91b6658, path=0x91b26a8)
    at cairo-gstate.c:761
#8  0x00176dab in *INT_cairo_stroke_preserve (cr=0x91b26a0) at cairo.c:1536
#9  0x00176d59 in cairo_stroke (cr=0x91b26a0) at cairo.c:1511
#10 0x002908a5 in cairogen_bezier (job=0x520c78, A=0x91b6770, n=7,
    arrow_at_start=0, arrow_at_end=0, filled=0) at gvrender_cairo.c:945




More information about the cairo mailing list