summaryrefslogtreecommitdiffstats
path: root/libdimension/canvas.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2010-04-07 14:26:15 -0400
committerTavian Barnes <tavianator@gmail.com>2010-04-07 14:34:52 -0400
commit2b087cb45ae91f90492a935625570d7d42ee3ecb (patch)
treea464213b08d04c8c91c8879a84e534f895c84378 /libdimension/canvas.c
parent7d6663eeb68bf9d0a3dff86128827c0c1d85df69 (diff)
downloaddimension-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/canvas.c')
-rw-r--r--libdimension/canvas.c27
1 files changed, 9 insertions, 18 deletions
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 <pthread.h>
#include <errno.h>
-#include <stdlib.h> /* For malloc(), free() */
+#include <stdlib.h> /* 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;
}