]> granicus.if.org Git - graphviz/commitdiff
webp_format: squash -Wsign-conversion warnings
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Thu, 31 Mar 2022 03:30:34 +0000 (20:30 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 2 Apr 2022 00:07:11 +0000 (17:07 -0700)
plugin/webp/gvdevice_webp.c

index 4331a8229b8dddc86afdc0e9d4431e7692ef8f50..6bded0c7676036a8f223b1e5852a5035f9e3d470 100644 (file)
@@ -55,9 +55,17 @@ static void webp_format(GVJ_t * job)
        goto Error;
     }
 
-    picture.width = job->width;
-    picture.height = job->height;
-    stride = 4 * job->width;
+    // if either dimension exceeds the WebP API, map this to one of its errors
+    if ((unsigned)INT_MAX / 4 < job->width || job->height > (unsigned)INT_MAX) {
+       int error = VP8_ENC_ERROR_BAD_DIMENSION;
+       fprintf(stderr, "Error! Cannot encode picture as WebP\n");
+       fprintf(stderr, "Error code: %d (%s)\n", error, kErrorMessages[error]);
+       goto Error;
+    }
+
+    picture.width = (int)job->width;
+    picture.height = (int)job->height;
+    stride = 4 * (int)job->width;
 
     picture.writer = writer;
     picture.custom_ptr = job;