]> granicus.if.org Git - graphviz/commitdiff
GD plugin: use more appropriate type for points counting
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 8 Nov 2022 02:30:23 +0000 (18:30 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Fri, 11 Nov 2022 01:09:34 +0000 (17:09 -0800)
Squashes the compiler warning:

  gvrender_gd.c: In function 'gdgen_polygon':
  gvrender_gd.c:491:6: warning: conversion to 'long unsigned int' from 'int'
    may change the sign of the result [-Wsign-conversion]
        points = realloc(points, n * sizeof(gdPoint));
        ^

plugin/gd/gvrender_gd.c

index 960271c34b4751e6f372dffe0b6650eb98c8ea82..fc2d1394d952bc0b9e3f361c699100e078895255 100644 (file)
@@ -468,7 +468,7 @@ gdgen_bezier(GVJ_t * job, pointf * A, int n, int arrow_at_start,
 }
 
 static gdPoint *points;
-static int points_allocated;
+static size_t points_allocated;
 
 static void gdgen_polygon(GVJ_t * job, pointf * A, int n, int filled)
 {
@@ -487,9 +487,9 @@ static void gdgen_polygon(GVJ_t * job, pointf * A, int n, int filled)
     fill_ok = filled && obj->fillcolor.u.index != gdImageGetTransparent(im);
 
     if (pen_ok || fill_ok) {
-        if (n > points_allocated) {
-           points = realloc(points, n * sizeof(gdPoint));
-           points_allocated = n;
+        if (n > 0 && (size_t)n > points_allocated) {
+           points = realloc(points, (size_t)n * sizeof(gdPoint));
+           points_allocated = (size_t)n;
        }
         for (i = 0; i < n; i++) {
            points[i].x = ROUND(A[i].x);