summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Muizelaar <jeff@freiheit.infidigm.net>2007-08-17 21:21:30 -0400
committerJeff Muizelaar <jeff@freiheit.infidigm.net>2007-08-17 21:21:30 -0400
commit5b4e595a0ab4d44184349efdd9f46f561132c89f (patch)
tree51be8c8370db8f742e26365665f69c416e51e147
parentadebb20e932dde3931900bbe3c05ad99ff921e5c (diff)
Make sure we create the output image on failure.
-rw-r--r--buffer-diff.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/buffer-diff.c b/buffer-diff.c
index c6e37ad..cbfe986 100644
--- a/buffer-diff.c
+++ b/buffer-diff.c
@@ -120,11 +120,7 @@ image_buf_diff (void *buf, int width_a, int height_a, int stride_a,
status = read_png_argb32 (filename_b, &buf_b, &width_b, &height_b, &stride_b);
if (status) {
- // write out the buffer on failure
- FILE *png_file = fopen (filename_a, "wb");
- write_png_argb32 (buf_a, png_file, width_a, height_a, stride_a);
- fclose (png_file);
- return -1;
+ goto fail;
}
if (width_a != width_b ||
@@ -138,7 +134,7 @@ image_buf_diff (void *buf, int width_a, int height_a, int stride_a,
width_b, height_b, stride_b,
filename_a, filename_b);
free (buf_b);
- return -1;
+ goto fail;
}
buf_diff = xcalloc (stride_a * height_a, 1);
@@ -162,7 +158,17 @@ image_buf_diff (void *buf, int width_a, int height_a, int stride_a,
free (buf_diff);
return pixels_changed;
+
+fail:
+ {
+ // write out the buffer on failure
+ FILE *png_file = fopen (filename_a, "wb");
+ write_png_argb32 (buf_a, png_file, width_a, height_a, stride_a);
+ fclose (png_file);
+ return -1;
+ }
}
+
/* Image comparison code courtesy of Richard Worth <richard@theworths.org>
* Returns number of pixels changed, (or -1 on error).
* Also saves a "diff" image intended to visually show where the