From 2b087cb45ae91f90492a935625570d7d42ee3ecb Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 7 Apr 2010 14:26:15 -0400 Subject: 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. --- libdimension/canvas.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) (limited to 'libdimension/canvas.c') diff --git a/libdimension/canvas.c b/libdimension/canvas.c index d18d0b7..d6c3c23 100644 --- a/libdimension/canvas.c +++ b/libdimension/canvas.c @@ -21,33 +21,24 @@ #include "dimension.h" #include #include -#include /* For malloc(), free() */ +#include /* For free() */ /* Allocate a new canvas, of width x and height y */ dmnsn_canvas * dmnsn_new_canvas(unsigned int x, unsigned int y) { /* Allocate the dmnsn_canvas struct */ - dmnsn_canvas *canvas = malloc(sizeof(dmnsn_canvas)); + dmnsn_canvas *canvas = dmnsn_malloc(sizeof(dmnsn_canvas)); - if (canvas) { - /* Set the width and height */ - canvas->x = x; - canvas->y = y; + /* Set the width and height */ + canvas->x = x; + canvas->y = y; - /* Allocate room for the optimizers */ - canvas->optimizers = dmnsn_new_array(sizeof(dmnsn_canvas_optimizer)); + /* Allocate room for the optimizers */ + canvas->optimizers = dmnsn_new_array(sizeof(dmnsn_canvas_optimizer)); - /* Allocate the pixels */ - canvas->pixels = malloc(sizeof(dmnsn_color)*x*y); - if (!canvas->pixels) { - dmnsn_delete_canvas(canvas); - errno = ENOMEM; - return NULL; - } - } else { - errno = ENOMEM; - } + /* Allocate the pixels */ + canvas->pixels = dmnsn_malloc(sizeof(dmnsn_color)*x*y); return canvas; } -- cgit v1.2.3