summaryrefslogtreecommitdiffstats
path: root/libdimension/phong.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/phong.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/phong.c')
-rw-r--r--libdimension/phong.c21
1 files changed, 7 insertions, 14 deletions
diff --git a/libdimension/phong.c b/libdimension/phong.c
index 8188488..ae7b2ce 100644
--- a/libdimension/phong.c
+++ b/libdimension/phong.c
@@ -20,7 +20,6 @@
#include "dimension.h"
#include <errno.h>
-#include <stdlib.h> /* For malloc */
#include <math.h>
/*
@@ -55,20 +54,14 @@ dmnsn_finish *
dmnsn_new_phong_finish(double specular, double exp)
{
dmnsn_finish *finish = dmnsn_new_finish();
- if (finish) {
- double *params = malloc(2*sizeof(double));
- if (!params) {
- dmnsn_delete_finish(finish);
- errno = ENOMEM;
- return NULL;
- }
- params[0] = specular;
- params[1] = exp;
+ double *params = dmnsn_malloc(2*sizeof(double));
+ params[0] = specular;
+ params[1] = exp;
+
+ finish->ptr = params;
+ finish->specular_fn = &dmnsn_phong_specular_fn;
+ finish->free_fn = &free;
- finish->ptr = params;
- finish->specular_fn = &dmnsn_phong_specular_fn;
- finish->free_fn = &free;
- }
return finish;
}