aboutsummaryrefslogtreecommitdiff
path: root/webp.c
diff options
context:
space:
mode:
authorLeonardo Hernández Hernández <leohdz172@protonmail.com>2022-10-04 22:21:31 -0500
committerLeonardo Hernández Hernández <leohdz172@protonmail.com>2022-10-04 22:29:03 -0500
commit8f907d477f2bc48bd6580e6ce4c2547036be18b5 (patch)
tree8558ac3c895e0702e03a1fcbc77396ba5ba95281 /webp.c
parent65a150e7877af228fe05b9b22497709aa4f9133f (diff)
downloadwbg-8f907d477f2bc48bd6580e6ce4c2547036be18b5.tar.gz
webp: simplify error path
Diffstat (limited to 'webp.c')
-rw-r--r--webp.c27
1 files changed, 13 insertions, 14 deletions
diff --git a/webp.c b/webp.c
index 82aa493..2d5346c 100644
--- a/webp.c
+++ b/webp.c
@@ -15,6 +15,7 @@ webp_load(FILE *fp, const char *path)
uint8_t *file_data = NULL;
uint8_t *image_data = NULL;
size_t image_size;
+ bool ok = false;
pixman_image_t *pix = NULL;
pixman_format_code_t format;
int width, height, stride;
@@ -30,44 +31,42 @@ webp_load(FILE *fp, const char *path)
}
if (!(file_data = WebPMalloc(image_size + 1))) {
- goto err;
+ goto out;
}
clearerr(fp);
fread(file_data, image_size, 1, fp);
if (ferror(fp)) {
LOG_ERRNO("%s: failed to read", path);
- goto err;
+ goto out;
}
file_data[image_size] = '\0';
/* Verify it is a webp image */
if (!WebPGetInfo(file_data, image_size, NULL, NULL)) {
LOG_ERR("%s: not a WebP file", path);
- goto err;
+ goto out;
}
image_data = WebPDecodeRGBA(file_data, image_size, &width, &height);
if (image_data == NULL) {
- goto err;
+ goto out;
}
format = PIXMAN_x8b8g8r8;
stride = stride_for_format_and_width(format, width);
- pix = pixman_image_create_bits_no_clear(
- format, width, height, (uint32_t *)image_data, stride);
+ ok = NULL != (pix = pixman_image_create_bits_no_clear(
+ format, width, height, (uint32_t *)image_data, stride));
- if (pix == NULL) {
+ if (!ok) {
LOG_ERR("%s: failed to instantiate pixman image", path);
- goto err;
+ goto out;
}
+out:
WebPFree(file_data);
- return pix;
-
-err:
- WebPFree(file_data);
- WebPFree(image_data);
+ if (!ok)
+ WebPFree(image_data);
- return NULL;
+ return pix;
}