mempool: Reduce an assert into an error return for get_buddy()

If we ask for a buddy that is outside of our allocation that is an
error that should not happen with a power-of-two allocated zone...
However, since it has been seen in the wild, we can safely return that
there is no buddy rather than die in a too-late assert.

Reported-by: Anton Eliasson <devel@antoneliasson.se>
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
This commit is contained in:
Chris Wilson 2013-03-15 09:08:00 +00:00
parent 2c2dccf5a4
commit 01a8bf01c6

View file

@ -157,7 +157,8 @@ get_buddy (cairo_mempool_t *pool, size_t offset, int bits)
{
struct _cairo_memblock *block;
assert (offset + (1 << bits) <= pool->num_blocks);
if (offset + (1 << bits) >= pool->num_blocks)
return NULL; /* invalid */
if (BITTEST (pool, offset + (1 << bits) - 1))
return NULL; /* buddy is allocated */