From 2fb6b9020089beabce3003788b7e83f1cd17dd25 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Fri, 12 Nov 2021 18:32:29 -0800 Subject: [PATCH] gvcolor.c: use a size_t to squash a -Wsign-conversion warning --- cmd/tools/gvcolor.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/cmd/tools/gvcolor.c b/cmd/tools/gvcolor.c index 6cfaad14f..041d75908 100644 --- a/cmd/tools/gvcolor.c +++ b/cmd/tools/gvcolor.c @@ -19,6 +19,7 @@ /* if NC changes, a bunch of scanf calls below are in trouble */ #define NC 3 /* size of HSB color vector */ +#include #include #include typedef struct Agnodeinfo_t { @@ -111,7 +112,7 @@ static void init(int argc, char *argv[]) static void color(Agraph_t * g) { - int nn, i, j, cnt; + int nn, j, cnt; Agnode_t *n, *v, **nlist; Agedge_t *e; char *p; @@ -143,8 +144,10 @@ static void color(Agraph_t * g) /* assemble the sorted list of nodes and store the initial colors */ nn = agnnodes(g); - nlist = malloc(nn * sizeof(Agnode_t *)); - i = 0; + assert(nn >= 0); + size_t nnodes = (size_t)nn; + nlist = malloc(nnodes * sizeof(Agnode_t *)); + size_t i = 0; for (n = agfstnode(g); n; n = agnxtnode(g, n)) { nlist[i++] = n; if ((p = agget(n, "color"))) @@ -156,15 +159,15 @@ static void color(Agraph_t * g) maxrank = ND_relrank(n); } if (LR != Forward) - for (i = 0; i < nn; i++) { + for (i = 0; i < nnodes; i++) { n = nlist[i]; ND_relrank(n) = maxrank - ND_relrank(n); } - qsort((void *) nlist, (size_t) nn, sizeof(Agnode_t *), + qsort((void *) nlist, nnodes, sizeof(Agnode_t *), (int (*)(const void *, const void *)) cmpf); /* this is the pass that pushes the colors through the edges */ - for (i = 0; i < nn; i++) { + for (i = 0; i < nnodes; i++) { n = nlist[i]; /* skip nodes that were manually colored */ @@ -199,7 +202,7 @@ static void color(Agraph_t * g) } /* apply saturation adjustment and convert color to string */ - for (i = 0; i < nn; i++) { + for (i = 0; i < nnodes; i++) { double h, s, b, t; char buf[64]; -- 2.40.0