[cairo-path] Don't raise an error when attempting to create an empty path.

Generate a real empty path structure instead of returning
_cairo_path_nil, if we have been asked to create an empty path.

(Also add a couple of missing _cairo_error()s and an appropriate test
case.)

Spotted by Fred Kiefer.
This commit is contained in:
Chris Wilson 2007-10-01 17:59:57 +01:00
parent 042c382c09
commit b4f86638cc
2 changed files with 41 additions and 12 deletions

View file

@ -352,8 +352,10 @@ _cairo_path_create_in_error (cairo_status_t status)
return (cairo_path_t*) &_cairo_path_nil;
path = malloc (sizeof (cairo_path_t));
if (path == NULL)
if (path == NULL) {
_cairo_error (CAIRO_STATUS_NO_MEMORY);
return (cairo_path_t*) &_cairo_path_nil;
}
path->num_data = 0;
path->data = NULL;
@ -370,25 +372,34 @@ _cairo_path_create_internal (cairo_path_fixed_t *path_fixed,
cairo_path_t *path;
path = malloc (sizeof (cairo_path_t));
if (path == NULL)
if (path == NULL) {
_cairo_error (CAIRO_STATUS_NO_MEMORY);
return (cairo_path_t*) &_cairo_path_nil;
}
path->num_data = _cairo_path_count (path, path_fixed,
_cairo_gstate_get_tolerance (gstate),
flatten);
if (path->num_data <= 0) {
if (path->num_data < 0) {
free (path);
return (cairo_path_t*) &_cairo_path_nil;
}
path->data = _cairo_malloc_ab (path->num_data, sizeof (cairo_path_data_t));
if (path->data == NULL) {
free (path);
return (cairo_path_t*) &_cairo_path_nil;
}
if (path->num_data) {
path->data = _cairo_malloc_ab (path->num_data,
sizeof (cairo_path_data_t));
if (path->data == NULL) {
free (path);
_cairo_error (CAIRO_STATUS_NO_MEMORY);
return (cairo_path_t*) &_cairo_path_nil;
}
path->status = _cairo_path_populate (path, path_fixed,
gstate, flatten);
path->status = _cairo_path_populate (path, path_fixed,
gstate, flatten);
} else {
path->data = NULL;
path->status = CAIRO_STATUS_SUCCESS;
}
return path;
}
@ -413,8 +424,9 @@ cairo_path_destroy (cairo_path_t *path)
if (path == NULL || path == &_cairo_path_nil)
return;
free (path->data);
path->num_data = 0;
if (path->data)
free (path->data);
free (path);
}

View file

@ -125,6 +125,23 @@ draw (cairo_t *cr, int width, int height)
cairo_path_destroy (path);
cairo_destroy (cr_error);
/* first check that we can copy an empty path */
cairo_new_path (cr);
path = cairo_copy_path (cr);
if (path->status != CAIRO_STATUS_SUCCESS) {
cairo_test_log ("Error: cairo_copy_path returned status of %s\n",
cairo_status_to_string (path->status));
cairo_path_destroy (path);
return CAIRO_TEST_FAILURE;
}
if (path->num_data != 0) {
cairo_test_log ("Error: cairo_copy_path did not copy an empty path, returned path contains %d elements\n",
path->num_data);
cairo_path_destroy (path);
return CAIRO_TEST_FAILURE;
}
cairo_path_destroy (path);
/* We draw in the default black, so paint white first. */
cairo_save (cr);