[cairo-commit] 2 commits - src/cairo-surface.c test/nil-surface.c

Carl Worth cworth at kemper.freedesktop.org
Thu Feb 1 15:22:41 PST 2007


 src/cairo-surface.c |    6 ++++++
 test/nil-surface.c  |   11 +++++++++++
 2 files changed, 17 insertions(+)

New commits:
diff-tree 159359325d4f8306feef6bebabecb31cbf0b9bf5 (from 26ef4746e66dccd8e0eb651db3e7f2826c068029)
Author: Carl Worth <cworth at cworth.org>
Date:   Thu Feb 1 15:22:27 2007 -0800

    Fix crashes in cairo_surface_finish for NULL or nil
    
    Thanks to Stuart Parmenter for alerting us of this bug.

diff --git a/src/cairo-surface.c b/src/cairo-surface.c
index 2bff0da..07f7439 100644
--- a/src/cairo-surface.c
+++ b/src/cairo-surface.c
@@ -475,6 +475,12 @@ cairo_surface_finish (cairo_surface_t *s
 {
     cairo_status_t status;
 
+    if (surface == NULL)
+	return;
+
+    if (surface->ref_count == CAIRO_REF_COUNT_INVALID)
+	return;
+
     if (surface->finished) {
 	_cairo_surface_set_error (surface, CAIRO_STATUS_SURFACE_FINISHED);
 	return;
diff-tree 26ef4746e66dccd8e0eb651db3e7f2826c068029 (from 382e021ccb657ab1e342e0d0eee402ff5eb89e5d)
Author: Carl Worth <cworth at cworth.org>
Date:   Thu Feb 1 15:21:12 2007 -0800

    Add two tests of cairo_surface_finish to test/nil-surface.c
    
    This tests calling cairo_surface_finish with either NULL or
    with a nil surface, (either currently causes a crash).

diff --git a/test/nil-surface.c b/test/nil-surface.c
index 80cb290..3ae7126 100644
--- a/test/nil-surface.c
+++ b/test/nil-surface.c
@@ -102,6 +102,17 @@ draw (cairo_t *cr, int width, int height
 
     cairo_destroy (cr2);
 
+    /*
+     * 3. Test that cairo_surface_finish can accept NULL or a nil
+     *    surface without crashing.
+     */
+
+    cairo_surface_finish (NULL);
+
+    surface = cairo_image_surface_create_from_png ("___THIS_FILE_DOES_NOT_EXIST___");
+    cairo_surface_finish (surface);
+    cairo_surface_destroy (surface);
+
     return CAIRO_TEST_SUCCESS;
 }
 


More information about the cairo-commit mailing list