[cairo-commit] 2 commits - src/cairo-gstate.c test/.gitignore
test/line-width-zero.c test/Makefile.am
Carl Worth
cworth at kemper.freedesktop.org
Thu Mar 15 22:10:05 PDT 2007
src/cairo-gstate.c | 10 ++++++
test/.gitignore | 1
test/Makefile.am | 1
test/line-width-zero.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 91 insertions(+)
New commits:
diff-tree 133183d858aa632da3cec2a789dcc1e1203d778b (from 23caa0f43ba199371ab178cf3e827e449ee5935f)
Author: Carl Worth <cworth at cworth.org>
Date: Thu Mar 15 22:08:55 2007 -0700
Fix cairo_stroke_extents and cairo_in_stroke to not crash with line width of 0.0
This fixes the line-width-zero test case and the bug reported here:
Crash in cairo_stroke_extents whe line width is 0 and line cap is ROUND
(_cairo_pen_find_active_cw_vertex_index)
https://bugs.freedesktop.org/show_bug.cgi?id=10231
diff --git a/src/cairo-gstate.c b/src/cairo-gstate.c
index 6175df7..bacf516 100644
--- a/src/cairo-gstate.c
+++ b/src/cairo-gstate.c
@@ -915,6 +915,11 @@ _cairo_gstate_in_stroke (cairo_gstate_t
cairo_status_t status = CAIRO_STATUS_SUCCESS;
cairo_traps_t traps;
+ if (gstate->stroke_style.line_width <= 0.0) {
+ *inside_ret = FALSE;
+ return CAIRO_STATUS_SUCCESS;
+ }
+
_cairo_gstate_user_to_backend (gstate, &x, &y);
_cairo_traps_init (&traps);
@@ -1053,6 +1058,11 @@ _cairo_gstate_stroke_extents (cairo_gsta
cairo_status_t status;
cairo_traps_t traps;
+ if (gstate->stroke_style.line_width <= 0.0) {
+ *x1 = *y1 = *x2 = *y2 = 0.0;
+ return CAIRO_STATUS_SUCCESS;
+ }
+
_cairo_traps_init (&traps);
status = _cairo_path_fixed_stroke_to_traps (path,
diff-tree 23caa0f43ba199371ab178cf3e827e449ee5935f (from 562bd551bc5ca3f3858a66b9884a8525531153c8)
Author: Carl Worth <cworth at cworth.org>
Date: Thu Mar 15 21:58:20 2007 -0700
Add line-width-zero test which currently crashes.
The crash is described in this bug report:
Crash in cairo_stroke_extents whe line width is 0 and line cap is ROUND
(_cairo_pen_find_active_cw_vertex_index)
https://bugs.freedesktop.org/show_bug.cgi?id=10231
diff --git a/test/.gitignore b/test/.gitignore
index 6c4adfc..a6d21da 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -70,6 +70,7 @@ leaky-dash
leaky-polygon
line-width
line-width-scale
+line-width-zero
linear-gradient
linear-gradient-reflect
long-lines
diff --git a/test/Makefile.am b/test/Makefile.am
index 54928cf..eb89b9d 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -54,6 +54,7 @@ leaky-dash \
leaky-polygon \
line-width \
line-width-scale \
+line-width-zero \
linear-gradient \
linear-gradient-reflect \
long-lines \
diff --git a/test/line-width-zero.c b/test/line-width-zero.c
new file mode 100644
index 0000000..139a471
--- /dev/null
+++ b/test/line-width-zero.c
@@ -0,0 +1,79 @@
+/*
+ * Copyright © 2007 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author: Carl Worth <cworth at cworth.org>
+ */
+
+#include "cairo-test.h"
+
+/* This is a test case for the following bug:
+ *
+ * Crash in cairo_stroke_extents whe line width is 0 and line cap is ROUND
+ * (_cairo_pen_find_active_cw_vertex_index)
+ * https://bugs.freedesktop.org/show_bug.cgi?id=10231
+ */
+
+static cairo_test_draw_function_t draw;
+
+cairo_test_t test = {
+ "line-width-zero",
+ "Test all stroke operations and all cap,join styles with line width of zero",
+ 0, 0,
+ draw
+};
+
+static cairo_test_status_t
+draw (cairo_t *cr, int width, int height)
+{
+ double x1, y1, x2, y2;
+
+ cairo_move_to (cr, 0.0, 0.0);
+ cairo_line_to (cr, 100.0, 100.0);
+ cairo_set_line_width (cr, 0.0);
+
+ cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
+ cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER);
+ cairo_stroke_extents (cr, &x1, &y1, &x2, &y2);
+ cairo_in_stroke (cr, 50, 50);
+ cairo_stroke_preserve (cr);
+
+ cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
+ cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
+ cairo_stroke_extents (cr, &x1, &y1, &x2, &y2);
+ cairo_in_stroke (cr, 50, 50);
+ cairo_stroke_preserve (cr);
+
+ cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
+ cairo_set_line_join (cr, CAIRO_LINE_JOIN_BEVEL);
+ cairo_stroke_extents (cr, &x1, &y1, &x2, &y2);
+ cairo_in_stroke (cr, 50, 50);
+ cairo_stroke (cr);
+
+ return CAIRO_TEST_SUCCESS;
+}
+
+int
+main (void)
+{
+ return cairo_test (&test);
+}
More information about the cairo-commit
mailing list