[PATCH] [output-stream] Protect against NULL write_func.

Chris Wilson chris at chris-wilson.co.uk
Wed Oct 15 14:24:32 PDT 2008


Allow the user to specify a NULL write_func for the output stream so that
a dummy surface can be created, for example, for querying target font
options or font extents.

Currently we do not perform any sanity checks at the user entry point and
will generate a mysterious SEGV during cairo_surface_finish() - which may
not immediately be obvious that it is due to a NULL write_func.
---
 src/cairo-output-stream.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/src/cairo-output-stream.c b/src/cairo-output-stream.c
index d02b277..bae6ac4 100644
--- a/src/cairo-output-stream.c
+++ b/src/cairo-output-stream.c
@@ -116,6 +116,9 @@ closure_write (cairo_output_stream_t *stream,
     cairo_output_stream_with_closure_t *stream_with_closure =
 	(cairo_output_stream_with_closure_t *) stream;
 
+    if (stream_with_closure->write_func == NULL)
+	return CAIRO_STATUS_SUCCESS;
+
     return stream_with_closure->write_func (stream_with_closure->closure,
 					    data, length);
 }
-- 
1.5.6.3


--=-qBgMwfM4jwl8MXBlvCG5--



More information about the cairo mailing list