From 45a3499b16d1083275db35a27f6a157fe9eb3b2c Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Thu, 7 Jul 2022 17:24:05 -0700 Subject: [PATCH] neatogen cmpIpair: 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/neatogen/multispline.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/neatogen/multispline.c b/lib/neatogen/multispline.c index 44d6a9f27..f8cfcaa65 100644 --- a/lib/neatogen/multispline.c +++ b/lib/neatogen/multispline.c @@ -170,7 +170,13 @@ static int cmpIpair(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 void *newIpair(Dt_t * d, Ipair * objp, Dtdisc_t * disc) -- 2.40.0