diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2010-05-07 22:35:18 +0100 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2010-05-07 22:35:18 +0100 |
commit | 81f4dd65a32efae645b826b84e8382f7bf7a9b2d (patch) | |
tree | 800d78de051577ce5350274842a71dc4c0d73fb0 | |
parent | a61570a55e70040ffcf8ff3cb2c7943e71a5e2a0 (diff) |
cairo: Special case cairo_t with NULL_POINTER
Avoid allocation for the potential user error of attempting to use
cairo_create(NULL).
-rw-r--r-- | src/cairo.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/cairo.c b/src/cairo.c index b417f55b..0070f983 100644 --- a/src/cairo.c +++ b/src/cairo.c @@ -70,6 +70,26 @@ static const cairo_t _cairo_nil = { }} }; +static const cairo_t _cairo_nil__null_pointer = { + CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ + CAIRO_STATUS_NULL_POINTER, /* status */ + { 0, 0, 0, NULL }, /* user_data */ + NULL, /* gstate */ + {{ 0 }, { 0 }}, /* gstate_tail */ + NULL, /* gstate_freelist */ + {{ /* path */ + { 0, 0 }, /* last_move_point */ + { 0, 0 }, /* current point */ + FALSE, /* has_current_point */ + FALSE, /* has_last_move_point */ + FALSE, /* has_curve_to */ + FALSE, /* is_box */ + FALSE, /* maybe_fill_region */ + TRUE, /* is_empty_fill */ + { {0, 0}, {0, 0}}, /* extents */ + {{{NULL,NULL}}} /* link */ + }} +}; #include <assert.h> /** @@ -231,7 +251,9 @@ cairo_create (cairo_surface_t *target) cairo_status_t status; /* special case OOM in order to avoid another allocation */ - if (target && target->status == CAIRO_STATUS_NO_MEMORY) + if (target == NULL) + return (cairo_t *) &_cairo_nil__null_pointer; + if (target->status == CAIRO_STATUS_NO_MEMORY) return (cairo_t *) &_cairo_nil; cr = _context_get (); |