From 41c8eefc6d432ab213f6f405c3d6346adb7f7931 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Wed, 15 Oct 2008 22:24:32 +0100 Subject: [PATCH] [output-stream] Protect against NULL write_func. 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 file changed, 3 insertions(+) diff --git a/src/cairo-output-stream.c b/src/cairo-output-stream.c index d02b277f2..bae6ac4fe 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); }