diff options
author | Tavian Barnes <tavianator@gmail.com> | 2010-04-07 14:26:15 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2010-04-07 14:34:52 -0400 |
commit | 2b087cb45ae91f90492a935625570d7d42ee3ecb (patch) | |
tree | a464213b08d04c8c91c8879a84e534f895c84378 /libdimension/solid_pigment.c | |
parent | 7d6663eeb68bf9d0a3dff86128827c0c1d85df69 (diff) | |
download | dimension-2b087cb45ae91f90492a935625570d7d42ee3ecb.tar.xz |
New dmnsn_malloc() function, and friends.
I'm tired of checking for malloc failures everywhere, considering it never
happens. So just bail out whenever it does. A lot of stuff is guaranteed
to succeed if it returns now.
Diffstat (limited to 'libdimension/solid_pigment.c')
-rw-r--r-- | libdimension/solid_pigment.c | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/libdimension/solid_pigment.c b/libdimension/solid_pigment.c index a69e25a..e414fc2 100644 --- a/libdimension/solid_pigment.c +++ b/libdimension/solid_pigment.c @@ -20,7 +20,6 @@ #include "dimension.h" #include <errno.h> -#include <stdlib.h> /* For malloc */ /* Solid color pigment callback */ static dmnsn_color dmnsn_solid_pigment_fn(const dmnsn_pigment *pigment, @@ -30,21 +29,14 @@ static dmnsn_color dmnsn_solid_pigment_fn(const dmnsn_pigment *pigment, dmnsn_pigment * dmnsn_new_solid_pigment(dmnsn_color color) { - dmnsn_color *solid; dmnsn_pigment *pigment = dmnsn_new_pigment(); - if (pigment) { - solid = malloc(sizeof(dmnsn_color)); - if (!solid) { - dmnsn_delete_pigment(pigment); - errno = ENOMEM; - return NULL; - } - *solid = color; - pigment->pigment_fn = &dmnsn_solid_pigment_fn; - pigment->free_fn = &free; - pigment->ptr = solid; - } + dmnsn_color *solid = dmnsn_malloc(sizeof(dmnsn_color)); + *solid = color; + + pigment->pigment_fn = &dmnsn_solid_pigment_fn; + pigment->free_fn = &free; + pigment->ptr = solid; return pigment; } |