]> granicus.if.org Git - graphviz/commitdiff
dotgen: squash -Wsign-conversion warnings in 'medians'
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 8 May 2022 23:41:17 +0000 (16:41 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 4 Jun 2022 03:37:48 +0000 (20:37 -0700)
The compiler says:

  mincross.c: In function 'medians':
  mincross.c:1803:25: warning: conversion to 'size_t' {aka 'long unsigned int'}
    from 'int' may change the sign of the result [-Wsign-conversion]
   1803 |             qsort(list, j, sizeof(int), (qsort_cmpf) ordercmpf);
        |                         ^

By doing array indexing in this function universally as `size_t` we can avoid
this.

lib/dotgen/mincross.c

index 943cac615fdd3cdf6be58062e4cc97b08e21cc07..89557aa64573bd6144d3171ce1297fa8b9637277 100644 (file)
@@ -1769,7 +1769,7 @@ static bool flat_mval(node_t * n)
 
 static bool medians(graph_t * g, int r0, int r1)
 {
-    int i, j, j0, lm, rm, lspan, rspan, *list;
+    int i, j0, lspan, rspan, *list;
     node_t *n, **v;
     edge_t *e;
     bool hasfixed = false;
@@ -1778,7 +1778,7 @@ static bool medians(graph_t * g, int r0, int r1)
     v = GD_rank(g)[r0].v;
     for (i = 0; i < GD_rank(g)[r0].n; i++) {
        n = v[i];
-       j = 0;
+       size_t j = 0;
        if (r1 > r0)
            for (j0 = 0; (e = ND_out(n).list[j0]); j0++) {
                if (ED_xpenalty(e) > 0)
@@ -1804,8 +1804,8 @@ static bool medians(graph_t * g, int r0, int r1)
                ND_mval(n) = list[j / 2];
            else {
                /* weighted median */
-               rm = j / 2;
-               lm = rm - 1;
+               size_t rm = j / 2;
+               size_t lm = rm - 1;
                rspan = list[j - 1] - list[rm];
                lspan = list[lm] - list[0];
                if (lspan == rspan)