/* if NC changes, a bunch of scanf calls below are in trouble */
#define NC 3 /* size of HSB color vector */
+#include <assert.h>
#include <cgraph/cgraph.h>
#include <stdlib.h>
typedef struct Agnodeinfo_t {
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;
/* 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")))
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 */
}
/* 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];