From: Matthew Fernandez Date: Fri, 8 Jul 2022 00:24:05 +0000 (-0700) Subject: neatogen cmpitem: rephrase comparator to avoid arithmetic X-Git-Tag: 5.0.1~32^2~5 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a235e4b6adad31f0ea0b43cedcfe071789fbd48a;p=graphviz neatogen cmpitem: 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/neatogen/constraint.c b/lib/neatogen/constraint.c index a6ad8caa1..1cc689774 100644 --- a/lib/neatogen/constraint.c +++ b/lib/neatogen/constraint.c @@ -38,7 +38,13 @@ static int cmpitem(Dt_t * d, int *p1, int *p2, Dtdisc_t * disc) (void)d; (void)disc; - return (*p1 - *p2); + if (*p1 < *p2) { + return -1; + } + if (*p1 > *p2) { + return 1; + } + return 0; } static Dtdisc_t constr = {