]> granicus.if.org Git - graphviz/commitdiff
GTK plugin: squash -Wsign-compare, -Wsign-conversion warnings for width/height
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Mon, 5 Sep 2022 17:22:42 +0000 (10:22 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 10 Sep 2022 19:01:11 +0000 (12:01 -0700)
Graphviz deals with these values as unsigned, but the GTK APIs deal with them as
signed. Nevertheless we expect both sides to only ever deal in non-negative
values.

plugin/gtk/callbacks.c

index 9e0cfe00bb67cc3a396ab8accd61749a28c326e5..d601e79771fc008e2a035fad3820b622c438cae4 100644 (file)
@@ -9,7 +9,7 @@
  *************************************************************************/
 
 #include "config.h"
-
+#include <assert.h>
 #include <gtk/gtk.h>
 #include <stdbool.h>
 
@@ -227,8 +227,10 @@ on_drawingarea1_expose_event           (GtkWidget       *widget,
 
     job->context = cr;
     job->external_context = true;
-    job->width = widget->allocation.width;
-    job->height = widget->allocation.height;
+    assert(widget->allocation.width >= 0);
+    job->width = (unsigned)widget->allocation.width;
+    assert(widget->allocation.height >= 0);
+    job->height = (unsigned)widget->allocation.height;
     if (job->has_been_rendered) {
        (job->callbacks->refresh)(job);
     }
@@ -297,8 +299,10 @@ on_drawingarea2_expose_event           (GtkWidget       *widget,
 
     job->context = cr;
     job->external_context = true;
-    job->width = widget->allocation.width;
-    job->height = widget->allocation.height;
+    assert(widget->allocation.width >= 0);
+    job->width = (unsigned)widget->allocation.width;
+    assert(widget->allocation.height >= 0);
+    job->height = (unsigned)widget->allocation.height;
 
     tmp = job->zoom;
     job->zoom = MIN(job->width * POINTS_PER_INCH / (job->bb.UR.x * job->dpi.x),
@@ -352,10 +356,13 @@ on_drawingarea1_configure_event        (GtkWidget       *widget,
                          (double) event->height / (double) job->height);
        job->zoom *= zoom_to_fit;
     }
-    if (event->width > job->width || event->height > job->height)
+    if ((event->width >= 0 && (unsigned)event->width > job->width) ||
+        (event->height >= 0 && (unsigned)event->height > job->height))
        job->has_grown = true;
-    job->width = event->width;
-    job->height = event->height;
+    assert(event->width >= 0);
+    job->width = (unsigned)event->width;
+    assert(event->height >= 0);
+    job->height = (unsigned)event->height;
     job->needs_refresh = true;
 
     return FALSE;