From bccd1ae4058552605da5528341e08700d36c0153 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Thu, 7 Jul 2022 17:24:05 -0700 Subject: [PATCH] gvcolor cmpf: 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. --- cmd/tools/gvcolor.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/tools/gvcolor.c b/cmd/tools/gvcolor.c index d60b607dc..e0a1d872c 100644 --- a/cmd/tools/gvcolor.c +++ b/cmd/tools/gvcolor.c @@ -53,11 +53,11 @@ extern char *colorxlate(char *str, char *buf); static int cmpf(Agnode_t ** n0, Agnode_t ** n1) { - double t; - t = ND_relrank(*n0) - ND_relrank(*n1); - if (t < 0.0) + double relrank0 = ND_relrank(*n0); + double relrank1 = ND_relrank(*n1); + if (relrank0 < relrank1) return -1; - if (t > 0.0) + if (relrank0 > relrank1) return 1; return 0; } -- 2.40.0