From ef5f460eb1f86a73e016c1150723ae1e70b3b037 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Thu, 4 Oct 2007 09:08:46 +0100 Subject: [PATCH] [cairo-path] Check for an empty path in cairo_append_path(). As we now generate empty paths, we must be able to handle empty paths in the user facing API. cairo_append_path() has an explicit check, and raises an error, for a NULL path->data, so we need to check the path->num_data first for empty paths. --- src/cairo.c | 3 +++ test/copy-path.c | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/cairo.c b/src/cairo.c index 4e3bfda40..4a1c73b71 100644 --- a/src/cairo.c +++ b/src/cairo.c @@ -3415,6 +3415,9 @@ cairo_append_path (cairo_t *cr, return; } + if (path->num_data == 0) + return; + if (path->data == NULL) { _cairo_set_error (cr, CAIRO_STATUS_NULL_POINTER); return; diff --git a/test/copy-path.c b/test/copy-path.c index 256f46123..362bb34d3 100644 --- a/test/copy-path.c +++ b/test/copy-path.c @@ -141,7 +141,13 @@ draw (cairo_t *cr, int width, int height) cairo_path_destroy (path); return CAIRO_TEST_FAILURE; } + cairo_append_path (cr, path); cairo_path_destroy (path); + if (cairo_status (cr) != CAIRO_STATUS_SUCCESS) { + cairo_test_log ("Error: cairo_append_path failed with a copy of an empty path, returned status of %s\n", + cairo_status_to_string (cairo_status (cr))); + return CAIRO_TEST_FAILURE; + } /* We draw in the default black, so paint white first. */ cairo_save (cr); @@ -224,6 +230,15 @@ main (void) path.num_data = 0; path.status = CAIRO_STATUS_SUCCESS; cairo_append_path (cr, &path); + if (cairo_status (cr) != CAIRO_STATUS_SUCCESS) + return 1; + cairo_destroy (cr); + + cr = cairo_create (surface); + path.data = NULL; + path.num_data = 1; + path.status = CAIRO_STATUS_SUCCESS; + cairo_append_path (cr, &path); if (cairo_status (cr) != CAIRO_STATUS_NULL_POINTER) return 1; cairo_destroy (cr);