From: Matthew Fernandez Date: Fri, 8 Jul 2022 00:24:05 +0000 (-0700) Subject: dotgen edgeposcmpf: rephrase comparator to avoid arithmetic X-Git-Tag: 5.0.1~32^2~7 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e0584ac2067d000e2ecbaa98d1e8f5e62b4ce705;p=graphviz dotgen edgeposcmpf: rephrase comparator to avoid arithmetic cccb8b1d22a18031fc92d93133c7fa14ef7e1361 fixed an integer overflow in a `memcmp`-/`strcmp`-like comparator. The same situation exists in the code touched in this commit. Rather than wait for an edge case to expose an overflow here, this change makes the same update, removing arithmetic and the consequent possibility of overflow. --- diff --git a/lib/dotgen/mincross.c b/lib/dotgen/mincross.c index 2bb108818..85bd4f461 100644 --- a/lib/dotgen/mincross.c +++ b/lib/dotgen/mincross.c @@ -1843,7 +1843,13 @@ static int nodeposcmpf(node_t ** n0, node_t ** n1) static int edgeidcmpf(edge_t ** e0, edge_t ** e1) { - return (AGSEQ(*e0) - AGSEQ(*e1)); + if (AGSEQ(*e0) < AGSEQ(*e1)) { + return -1; + } + if (AGSEQ(*e0) > AGSEQ(*e1)) { + return 1; + } + return 0; } /* following code deals with weights of edges of "virtual" nodes */