From e0584ac2067d000e2ecbaa98d1e8f5e62b4ce705 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Thu, 7 Jul 2022 17:24:05 -0700 Subject: [PATCH] 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. --- lib/dotgen/mincross.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 */ -- 2.40.0