From 8e50a0b08f8bafc24904d58ad22b4381a77d529c Mon Sep 17 00:00:00 2001 From: Vincent Rabaud Date: Thu, 26 Oct 2023 17:21:37 +0200 Subject: [PATCH] Check return values of WebP API functions. Those will be made nodiscard at some point. --- src/libguac/encode-webp.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/libguac/encode-webp.c b/src/libguac/encode-webp.c index 43c5a00c5d..1314955e48 100644 --- a/src/libguac/encode-webp.c +++ b/src/libguac/encode-webp.c @@ -198,16 +198,22 @@ int guac_webp_write(guac_socket* socket, guac_stream* stream, config.method = 2; /* Compression method (0=fast/larger, 6=slow/smaller) */ /* Validate configuration */ - WebPValidateConfig(&config); + if (!WebPValidateConfig(&config)) { + return -1; + } /* Set up WebP picture */ - WebPPictureInit(&picture); + if (!WebPPictureInit(&picture)) { + return -1; + } picture.use_argb = 1; picture.width = width; picture.height = height; /* Allocate and init writer */ - WebPPictureAlloc(&picture); + if (!WebPPictureAlloc(&picture)) { + return -1; + } picture.writer = guac_webp_stream_write; picture.custom_ptr = &writer; guac_webp_stream_writer_init(&writer, socket, stream); @@ -244,7 +250,7 @@ int guac_webp_write(guac_socket* socket, guac_stream* stream, } /* Encode image */ - WebPEncode(&config, &picture); + const int result = WebPEncode(&config, &picture) ? 0 : -1; /* Free picture */ WebPPictureFree(&picture); @@ -252,7 +258,7 @@ int guac_webp_write(guac_socket* socket, guac_stream* stream, /* Ensure all data is written */ guac_webp_flush_data(&writer); - return 0; + return result; }