[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.
This commit is contained in:
Chris Wilson 2007-10-04 09:08:46 +01:00
parent 8ad56b308a
commit ef5f460eb1
2 changed files with 18 additions and 0 deletions

View file

@ -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;

View file

@ -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);