diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2007-10-01 17:59:57 +0100 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2007-10-01 17:59:57 +0100 |
commit | b4f86638cc4b87bfaf10568ae9beb89626e26613 (patch) | |
tree | 504f774d84f53f7e37dfcac70e690c5d08948e91 /src/cairo-path.c | |
parent | 042c382c094d1ea6f9a5a162d4d1d9ac83413233 (diff) | |
download | cairo-b4f86638cc4b87bfaf10568ae9beb89626e26613.tar.gz |
[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.
Diffstat (limited to 'src/cairo-path.c')
-rw-r--r-- | src/cairo-path.c | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/src/cairo-path.c b/src/cairo-path.c index 0740ebc4c..b1ef44e27 100644 --- a/src/cairo-path.c +++ b/src/cairo-path.c @@ -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); } |