summaryrefslogtreecommitdiffstats
path: root/dimension/main.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 /dimension/main.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 'dimension/main.c')
-rw-r--r--dimension/main.c31
1 files changed, 3 insertions, 28 deletions
diff --git a/dimension/main.c b/dimension/main.c
index 9c7a5cf..8a268b9 100644
--- a/dimension/main.c
+++ b/dimension/main.c
@@ -214,11 +214,6 @@ main(int argc, char **argv) {
/* Allocate a canvas */
scene->canvas = dmnsn_new_canvas(width, height);
- if (!scene->canvas) {
- dmnsn_delete_scene(scene);
- fprintf(stderr, "Couldn't allocate canvas!\n");
- return EXIT_FAILURE;
- }
/* Set the new number of threads if --threads changed it */
if (nthreads)
@@ -231,30 +226,16 @@ main(int argc, char **argv) {
/* Generate a default output filename by replacing the extension of the
basename of the input file with ".png" */
if (!output) {
- char *input_copy = strdup(input);
- if (!input_copy) {
- fprintf(stderr, "Couldn't allocate space for output filename!\n");
- return EXIT_FAILURE;
- }
-
+ char *input_copy = dmnsn_strdup(input);
char *base = basename(input_copy);
char *ext = strrchr(base, '.');
if (ext) {
- output = malloc(ext - base + 5);
- if (!output) {
- fprintf(stderr, "Couldn't allocate space for output filename!\n");
- return EXIT_FAILURE;
- }
-
+ output = dmnsn_malloc(ext - base + 5);
strncpy(output, base, ext - base + 5);
ext = output + (ext - base);
} else {
size_t len = strlen(base);
- output = malloc(len + 5);
- if (!output) {
- fprintf(stderr, "Couldn't allocate space for output filename!\n");
- return EXIT_FAILURE;
- }
+ output = dmnsn_malloc(len + 5);
strcpy(output, base);
ext = output + len;
}
@@ -277,12 +258,6 @@ main(int argc, char **argv) {
}
dmnsn_progress *render_progress = dmnsn_raytrace_scene_async(scene);
- if (!render_progress) {
- dmnsn_delete_scene(scene);
- fprintf(stderr, "Error starting render!\n");
- return EXIT_FAILURE;
- }
-
dmnsn_progressbar(scene->nthreads > 1
? "Rendering scene with %u threads"
: "Rendering scene with %u thread",