Skip to content

Commit

Permalink
Check return values of WebP API functions.
Browse files Browse the repository at this point in the history
Those will be made nodiscard at some point anyway.
Issue GUACAMOLE-1875
  • Loading branch information
vrabaud committed Oct 27, 2023
1 parent bb14ee9 commit 7a1f1f5
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/libguac/encode-webp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -244,15 +250,15 @@ 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);

/* Ensure all data is written */
guac_webp_flush_data(&writer);

return 0;
return result;

}

0 comments on commit 7a1f1f5

Please sign in to comment.