From bcd684c3f21c6fba8cbff1658bace5032d35211f Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Thu, 7 Jul 2022 17:24:05 -0700 Subject: [PATCH] patchwork nodecmp: 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/patchwork/patchwork.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/patchwork/patchwork.c b/lib/patchwork/patchwork.c index fb3d20101..22e2c6d1e 100644 --- a/lib/patchwork/patchwork.c +++ b/lib/patchwork/patchwork.c @@ -130,11 +130,13 @@ static treenode_t *mkTree (Agraph_t * g, attrsym_t* gp, attrsym_t* ap, attrsym_t static int nodecmp (treenode_t** p0, treenode_t** p1) { - double diff = (*p0)->area - (*p1)->area; - - if (diff < 0) return 1; - else if (diff > 0) return -1; - else return 0; + if ((*p0)->area < (*p1)->area) { + return 1; + } + if ((*p0)->area > (*p1)->area) { + return -1; + } + return 0; } static void layoutTree(treenode_t * tree) -- 2.40.0