]> granicus.if.org Git - graphviz/commitdiff
pathplan: use a 'size_t' for counting allocated points
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 13 Nov 2022 18:09:13 +0000 (10:09 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 13 Nov 2022 22:55:46 +0000 (14:55 -0800)
Squashes:

  shortest.c:500:41: warning: conversion to ‘long unsigned int’ from ‘int’ may
    change the sign of the result [-Wsign-conversion]
    500 |     pnls = realloc(pnls, POINTNLINKSIZE * newpnln);
        |                                         ^
  shortest.c:505:44: warning: conversion to ‘long unsigned int’ from ‘int’ may
    change the sign of the result [-Wsign-conversion]
    505 |     pnlps = realloc(pnlps, POINTNLINKPSIZE * newpnln);
        |                                            ^

It would be nice to adjust `Ppoly_t.pn` to avoid the casting, but it is part of
the public API and it does not seem worth an API break for this.

lib/pathplan/shortest.c

index 1ae078f4bc638d4db4741e62d8382a78e761c22c..8ffc2fc16d2196ee35173ed7adc848cf4aabe69d 100644 (file)
@@ -8,6 +8,7 @@
  * Contributors: Details at https://graphviz.org
  *************************************************************************/
 
+#include <assert.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -55,7 +56,8 @@ typedef struct deque_t {
 } deque_t;
 
 static pointnlink_t *pnls, **pnlps;
-static int pnln, pnll;
+static size_t pnln;
+static int pnll;
 
 static triangle_t *tris;
 static int trin, tril;
@@ -80,7 +82,7 @@ static bool intersects(Ppoint_t *, Ppoint_t *, Ppoint_t *, Ppoint_t *);
 static bool between(Ppoint_t *, Ppoint_t *, Ppoint_t *);
 static int pointintri(long, Ppoint_t *);
 
-static int growpnls(int);
+static int growpnls(size_t);
 static int growtris(int);
 static int growdq(int);
 static int growops(int);
@@ -105,7 +107,8 @@ int Pshortestpath(Ppoly_t * polyp, Ppoint_t eps[2], Ppolyline_t * output)
 #endif
 
     /* make space */
-    if (growpnls(polyp->pn) != 0)
+    assert(polyp->pn >= 0);
+    if (growpnls((size_t)polyp->pn) != 0)
        return -2;
     pnll = 0;
     tril = 0;
@@ -493,8 +496,7 @@ static int pointintri(long trii, Ppoint_t *pp) {
     return sum == 3 || sum == 0;
 }
 
-static int growpnls(int newpnln)
-{
+static int growpnls(size_t newpnln) {
     if (newpnln <= pnln)
        return 0;
     pnls = realloc(pnls, POINTNLINKSIZE * newpnln);