From 1724797a27633276e7b8db4a3566086313a51bd1 Mon Sep 17 00:00:00 2001 From: Andri Yngvason Date: Thu, 2 Apr 2020 21:12:09 +0000 Subject: [PATCH] tight: Add some error handling --- src/tight.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/tight.c b/src/tight.c index 3e153b5..811d79d 100644 --- a/src/tight.c +++ b/src/tight.c @@ -20,6 +20,7 @@ #include "fb.h" #include "tight.h" #include "common.h" +#include "logging.h" #include #include @@ -86,11 +87,18 @@ int tight_encode_box(struct vec* dst, struct nvnc_client* client, vec_append(dst, &rect, sizeof(rect)); tjhandle handle = tjInitCompress(); + if (!handle) + return -1; void* img = (uint32_t*)fb->addr + x + y * stride; - tjCompress2(handle, img, width, stride * 4, height, tjfmt, &buffer, - &size, TJSAMP_422, quality, TJFLAG_FASTDCT); + int rc = -1; + rc = tjCompress2(handle, img, width, stride * 4, height, tjfmt, &buffer, + &size, TJSAMP_422, quality, TJFLAG_FASTDCT); + if (rc < 0) { + log_error("Failed to encode tight JPEG box: %s\n", tjGetErrorStr()); + goto compress_failure; + } vec_fast_append_8(dst, TIGHT_JPEG); @@ -98,10 +106,12 @@ int tight_encode_box(struct vec* dst, struct nvnc_client* client, vec_append(dst, buffer, size); + rc = 0; tjFree(buffer); +compress_failure: tjDestroy(handle); - return 0; + return rc; } int tight_encode_frame(struct vec* dst, struct nvnc_client* client,