Commit graph

3660 commits

Author SHA1 Message Date
Carl Worth
7c97696af9 Make _cairo_path_bounder_add_point void
Yet another function that cannot fail under any circumstances.
2007-04-09 17:16:30 -07:00
Carl Worth
93776772ed Make _cairo_matrix_compute_scale_factors void
Yet another function that cannot fail under any circumstances.
2007-04-09 17:15:33 -07:00
Carl Worth
d5b35d7d76 Make _cairo_pen_init_empty void
Yet another function that cannot fail under any circumstances.
2007-04-09 17:12:11 -07:00
Carl Worth
9077da99ab Make _cairo_gstate_user_to_device (and friends) void.
This is just multiplication after all, so there's nothing that can fail.
And we can get rid of a lot of useless error-checking code this way.
The corrected functions are:

	_cairo_gstate_user_to_device
	_cairo_gstate_user_to_device_distance
	_cairo_gstate_device_to_user
	_cairo_gstate_device_to_user_distance
2007-04-09 17:09:51 -07:00
Carl Worth
628ec8eb91 Make _cairo_gstate_identity_matrix void
Now that we have the warn_unused_result attribute enabled, (thanks
Chris!), it's actually harmful to have a function return an
uncoditional value of CAIRO_STATUS_SUCCESS. The harm is that
it would force lots of unnecessary error-checking paths that
just add clutter.

It is much better to simply give a function that cannot fail
a return type of void.
2007-04-09 17:03:29 -07:00
Chris Wilson
90803eca0f Implement clone_surface for test-fallback-surface.
A few tests were failing due to clip_init_deep_copy() not being able to
clone the target surface. Before propagating the failure, this was being
silently ignored.

Copy the simple implementation from cairo-image-surface.
2007-04-09 16:50:20 -07:00
Chris Wilson
4456ecbf26 Fix detection of FcFini().
It is customary to check for a FontConfig function in the FontConfig
library rather than the FreeType library.
2007-04-09 16:49:58 -07:00
Chris Wilson
cd2394c076 Free the bitmap->buffer on failure
Currently if the ownership of the bitmap->buffer is passed to
_get_bitmap_surface() then the status of the buffer is inconsistent
should the function detect an error (i.e. CAIRO_STATUS_NO_MEMORY).
Fix it up that should we encounter an error and we own the buffer then
we always free it on behalf of the caller.
2007-04-09 16:48:02 -07:00
Chris Wilson
ac33953a81 Correct handling of a malloc failure during pattern_create_in_error()
Confusion had been introduced as to who provided the fixup after
the malloc failed which resulted in a NULL deference whilst checking for
an erroneous pattern in _cairo_pattern_create_in_error.
2007-04-09 16:47:38 -07:00
Behdad Esfahbod
b6924722b8 [cairo-skiplist] Use one random number per insertion, instead of two 2007-04-09 19:39:50 -04:00
Chris Wilson
ce1651f1ea Free the pixman_image if we fail to wrap it with a surface. 2007-04-09 16:39:05 -07:00
Chris Wilson
bd99507f15 Initialise cairo_spline_t to use its embedded buffer.
Currently the code defaults to setting its points to NULL and fixing it up
on the first add_point() to use the embedded buffer. Skip this extra step
by initialising points to the embedded buffer.
2007-04-09 16:38:29 -07:00
Behdad Esfahbod
6daaf8a89d [cairo-skiplist] Reduce MAX_LEVEL from 31 to 15
The probability that a node of level L is generated is
0.25^(L-1) * 0.75.  It means, a node of level 15 or
more will be used with a probability of about 3 * 10^-9.
That's really rare...

Actually that's not still true, because the level of a new
node is capped by current max-level plus one.  So to really
get a node with a level of 15 one should first get a node
of level 2, then 3, then 4, ..., finally 15.  Now that's
REALLY rare.

And guess what, the skiplist only start behaving bad with a
max level cap of MAX_LEVEL when having on the order of
4**MAX_LEVEL items in it.  I really hope we don't get there.
2007-04-09 19:38:22 -04:00
Behdad Esfahbod
a7de9501f6 [cairo-skiplist] Group levels two-by-two in freelists
Most memory allocators allocate in multiples of twice the size of
a pointer.  So there is no point in keeping freelists for both
even and odd levels.  We now round odd levels up to the next
even level for freelist computations.  This reduces the number of
node mallocations.
2007-04-09 19:38:08 -04:00
Chris Wilson
b2280c5ac2 Do not overwrite cr->status
The idiom for cairo.c is to do
    cr->status = _cairo_op ();
    if (cr->status) _cairo_set_error (cr, cr->status);

Unfortunately a trivial mistake for a _cairo_op () is to call a cairo_op ()
and forget to check cr->status but return CAIRO_STATUS_SUCCESS which will
mask the earlier error.

Obviously this is a bug in the lower level but the impact can be reduced
by chaning cairo.c to use a local status variable for its return:
    cairo_status_t status = _cairo_op ();
    if (status) _cairo_set_error (cr, cr->status);
2007-04-09 16:36:59 -07:00
Chris Wilson
14ac5dd78b Return the correct status from _cairo_pen_stroke_spline().
The return value is shared before the normal cleanup and error paths,
so do not simply return a hard-coded CAIRO_STATUS_SUCCESS.
2007-04-09 16:23:36 -07:00
Chris Wilson
b823e2f68f cairo-xlib-surface - propagate status returns.
These were found during a cairo_static pass on an alternative branch...

A critical one in particular was setting the have added glyph flag to
TRUE even if _cairo_xlib_surface_add_glyph() fails. This can cause an
application crash due to a RenderBadGlyph error later when the scaled
font is cleaned and we attempt to remove the glyph.
2007-04-09 16:22:48 -07:00
Chris Wilson
4a624b8e8b Remove the entry if we return an error code during _cair_hash_table_insert.
Previously if we detected an error during resize we would report a
failure to insert the entry into the hash table having already done so.
2007-04-09 16:19:41 -07:00
Chris Wilson
1cdb54f883 Reorder cleanup cairo_xlib_surface_show_glyphs()
_cairo_pattern_release_surface() asserts that it is passed a pattern
surface. This itself is bad as breaks the symmetry with
_cairo_pattern_acquire_surface under() error conditions, however reorder
the cleanup to avoid this assertion.
2007-04-09 16:18:29 -07:00
Chris Wilson
a1331fb043 Detect failure to allocate glyphs during _cairo_scaled_font_init()
If _cairo_cache_create fails, return CAIRO_STATUS_NO_MEMORY.
2007-04-09 16:13:41 -07:00
Chris Wilson
1237eedff3 Check for error whilst trying to advance along a text string.
The text perf-case tries to fill the region with a single text string,
but fails to detect when the current point does not advance due to an
error. This causes the perf-case to enter an infinite loop, so we break
out when the cairo_status() has been set.
2007-04-09 16:13:16 -07:00
Chris Wilson
ea4945850a Avoid using substituted surfaces for xlib operations.
Detect when a substitute image surface is returned for a solid pattern,
and avoid mixed image/xlib composite operations. This can happen for example
if there is a resource allocation failure during creating a similar surface.
2007-04-09 16:12:41 -07:00
Chris Wilson
751976970b Handle failure to allocate a GC. 2007-04-09 16:11:22 -07:00
Chris Wilson
c6055dc349 Reset cairo_scaled_font_map after freeing.
Along the error path the global font map was freed but not reset,
causing segfaults on any subsequent use of a cairo_scaled_font_t.
2007-04-09 16:08:21 -07:00
Chris Wilson
65de47d8bc cairo-bentley-ottmann - check init for failure
This was found during a cairo_static pass on an alternative branch...
Add the trivial error propagation for _cairo_bo_event_queue_init()
2007-04-09 16:08:00 -07:00
Chris Wilson
b4cb0306b4 cairo-type1-fallback - propagate error returns
Add status returns in order to propagate a matrix inversion failure
up through the call stack.
2007-04-09 16:06:51 -07:00
Chris Wilson
b29d78dda1 cairo-svg-surface - propagate some error returns
Add status returns to functions in order to propagate an error up
the call stack.

For the emit_*_pattern we add a new status return even when when
the functon return CAIRO_STATUS_SUCCESS unconditionally in order for
the caller to handle all cases in a consistent manner.
2007-04-09 16:05:30 -07:00
Chris Wilson
3f7ca6ef5b cairo-pen - cairo_pen_init() can fail propagate its error.
Add status returns in order to propagate an intialisation failure
back up the call chain.
2007-04-09 15:51:31 -07:00
Chris Wilson
67f13b3518 cairo-bentley-ottmann/skip-list - catch and propagate out-of-memory errors
The skip list inserts could return NULL indicating an out-of-memory error.
In order to handle this, propagate the error up the call stack.
2007-04-09 15:12:15 +01:00
Chris Wilson
293122279f cairo-path-stroke - add trivial missing status checks
Propagate the error status.
2007-04-09 15:11:47 +01:00
Chris Wilson
2f2bff038c buffer-diff - check for any errors whilst writing the png
Propagate any errors from writing out the png.
2007-04-09 15:08:45 +01:00
Chris Wilson
79424fc646 cairo - add missing status checks
Add a few missing status checks and set the error on the context when
applicable.
2007-04-09 15:08:29 +01:00
Chris Wilson
a34a32fd99 cairo-type1-fallback - check for an error during cleanup
The cleanup path is shared between the error path and the true path, and
so any error along it can not be ignored.
2007-04-09 15:07:27 +01:00
Chris Wilson
d2efadc84d cairo-svg-surface - propagate error returns
Add a couple of missing checks for error statues.
2007-04-09 15:07:10 +01:00
Chris Wilson
02264b40f5 cairo-surface-fallback - propagate error returns
_cairo_surface_composite() can fail so check for and error return and
propagate.
2007-04-09 15:06:49 +01:00
Chris Wilson
76b27fb0e8 cairo-ps-surface - add a couple of status checks
Handle a couple more error returns.
2007-04-09 15:06:25 +01:00
Chris Wilson
619425a8b3 cairo-polygon - trivial propagation of error status
_cairo_polygon_move_to() returns an error status so use it.
2007-04-09 15:06:11 +01:00
Chris Wilson
4b195779a4 cairo-pen - trivial propagation of error status
Add a couple of missing checks for error statuses and correct the
error path cleanup for _cairo_pen_stroke_spline().
2007-04-09 15:05:58 +01:00
Chris Wilson
66d3e25202 cairo-pdf-surface - propagate error status
Catch and propagate any error status.
2007-04-09 15:05:45 +01:00
Chris Wilson
b32a5b1dc6 cairo-pattern - propagate status
Catch, cleanup and propagate after an error return.
2007-04-09 15:05:35 +01:00
Chris Wilson
fd49bbb4b2 cairo-path - check for failure during _cairo_path_fixed_interpret
Catch an error return from _cairo_path_fixed_interpret() and return
it. Similary check for an error code in cairo_status() before returning
success.
2007-04-09 15:05:24 +01:00
Chris Wilson
814830f63b cairo-path-fill - trivial missing unused result
Actually assign the result that is tested on the next line...
2007-04-09 15:05:13 +01:00
Chris Wilson
7ab1f62c60 cairo-paginated-surface - fix up the trivial unused result
Check for status returns and propagate, cleaning up as necessary.
2007-04-09 15:04:58 +01:00
Chris Wilson
78c0d62ba7 cairo-meta-surface - propagate trivial status return
_cairo_path_fixed_init_copy() could fail so propagate it's status.
2007-04-09 15:04:47 +01:00
Chris Wilson
75cc5e04d5 cairo-image-surface - propagate error returns from pixman.
pixman does occasionally return an error - in such circumstances we
should propagate it.
2007-04-09 15:04:30 +01:00
Chris Wilson
dee9a53029 cairo-gstate - fix the trivial unchecked returns
Check for an error return and propagate.
2007-04-09 15:04:17 +01:00
Chris Wilson
de264af2c6 cairo-ft-font - handle trivial failures
Catch the status return, cleanup and propagate the error.
2007-04-09 15:03:59 +01:00
Chris Wilson
14c8dfb0b9 cairo-clip - handle trivial pixman failures
Detect the simple cases when pixman returns an error, ie an OOM
condition, and propagate the error status.
2007-04-09 15:03:34 +01:00
Chris Wilson
274c20c27a cairo-boilerplate - handle failure to set user data
After failing to set the user data on a surface, clean up and return NULL.
2007-04-09 15:02:17 +01:00
Chris Wilson
46eab95698 Add attribute(warn_unused_result)
This adds a compiler check that the function result is used by the caller
and enables it by default for all cairo_private functions and for public
API that returns a cairo_status_t.

It has been discussed that to extend the warnings to all functions, a
new function type could been introduced to cover static functions:
cairo_static. This has not been done at the present time in order to
minimise the churn and focus on the more common errors.

In order to reduce the warning spew generated by gcc for invalid use of
this attribute, -Wno-attributes is added to CFLAGS. This has the
unfortunate side-effect of masking future warnings for all attributes -
be warned!
2007-04-09 15:01:58 +01:00